Query un contrôle de winforms avec CheckedListBoxItemCollection.AsQueryable (). Provider.CreateQuery (

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

Question

Je dois interroger un contrôle WinForms ( CheckedListBoxControl ) ayant une CheckedListBoxItemCollection que je veux requête pour un certain Id qui est dans le propriété "Valeur" du 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);
}

Mise à jour:

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

Pourquoi dit Visual Studio que le IEnumerable ou l'espace de noms IEnumberable de celui-ci ne peut pas être trouvé? Quand je l'utilise « var » plutôt, je peux compiler mon code. Mais le patron de mon entreprise forbide utiliser mon var ...

Était-ce utile?

La solution

CheckListBox.Items n'implémente IEnumerable, non IEnumerable<T>. Vous obtenez la surcharge de AsQueryable () qui retourne IQueryable (pas le générique). Ce qui n'a que les acteurs et les méthodes d'extension OfType.

définissaient les articles de retour de l'objet au Ministère. Comme ceci:

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

Vous n'avez pas besoin AsQueryable () plus btw.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top