Hi,
Can any one tell me y contain method of ValueListItem does not work. I am trying to find a valuelistitem using
this
.ultraGrid2.DisplayLayout.ValueLists[MyValueList].ValueListItems.Contains(v1) where v1 is ValueListItem but it always gives me false.
While the same works fine if add any new valuelistitem and then try to find it.
ValueListItem.Remove() also works fine but not contain().
Please Help.
The only explanation I can think of is that the item is not in the collection. The Contains method will do a reference comparison, so if you create a ValueListItem instance with the same DataValue and DisplayText as one that exists in the collection, and pass that into the Contains method, it should not and does not return true since they are two different instances.
I am also having a problem with the Infragistics ValueListItems.Contains method not working.
If I run the following code, after having added a ValueListItem called 'Test' - If grdData.DisplayLayout.ValueLists.Contains("Test") ..., this return False
If I then try to add it again - grdData.DisplayLayout.ValueLists.Add("Test") - I get an error stating the key already exists.
Can you provide an example of how this should work?
Thanks
Andrew Hunot
Hi Andrew,
That is correct. The Contains method searches the collection for a matching object. In this case, the ValueLists collection does not contain any strings, it only contains ValueList objects, so you will never kind a string that way.
If you are looking for a ValueList whose key is "Test", then what you should do is use the Exists methods, which searches the keys.
Many thanks - this is just what I was after!
Regards
Andrew