الاستعلام عن عنصر تحكم winforms مع checkedBoxItemCollection.asqueryable (). Provider.Createquery (

StackOverflow https://stackoverflow.com/questions/3587449

سؤال

أحتاج إلى الاستعلام عن التحكم في WinForms (checkedListBoxControl) املك checkedListBoxItemCollection الذي أريد الاستعلام عنه لبعض هوية شخصية هذا هو ضمن "قيمة" الخاصية من checkedListBoxItem.

CheckedListBoxItemCollection items = myCheckedListBoxControl.Items;

foreach(Department dep in departmentList)
{
  bool isDepExisting = items.AsQueryable().Where( the .Where clause does not exist );
  // How can I query for the current dep.Id in the departmentList and compare this   dep.Id with  every Item.Value in the CheckedListBoxControl and return a bool from the result ???   
  if(!isDepExisting)
      myCheckedListBoxControl.Items.Add( new CheckedListBoxItem(dep.id);
}

تحديث:

IEnumberable<CheckedListBoxItem> checks = items.Cast<CheckedListBoxItem>().Where(item => item.Value.Equals(dep.InternalId));

لماذا لا يمكن العثور على استوديو Visual الذي لا يمكن العثور على مساحة الاسم القابلة للاستمتاع به؟ عندما أستخدم "var" بدلاً من ذلك ، يمكنني تجميع الكود الخاص بي. لكن الرئيس في شركتي ينعم بي لاستخدام فار ...

هل كانت مفيدة؟

المحلول

قائمة checkbox.items فقط تنفذ iEnumerable ، وليس IEnumerable<T>. يمكنك الحصول على الحمل الزائد من Asqueryable () الذي يعيد iqueryable (وليس العام العام). الذي يحتوي فقط على أساليب التمديد المدلى بها.

يلقي العناصر مرة أخرى من كائن إلى آخر. مثله:

var q = checkedListBox1.Items.Cast<Department>().AsQueryable().Where((d) => d.Id == 1);

لا تحتاج إلى asqueryable () بعد الآن راجع للشغل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top