Hi-
I have a grid in my form where in, from a particular column the user can select multiple items.So I have a text box with button control set to a win grid having check boxes. One more requirement is some of the rows should be pre-selected based on the values coming from a query from the database. Everything is working fine except when I get duplicate entries from the query. I can't modify the query not to return duplicates. So my problem is, when I get duplicate entries from the query I shouldn't add those to the ValueList property of the cell.
So I wrote a small code to restrict these duplicate entries like the below. But some how Contains method is returning false if it has a value in it.
If (condition met) Then If Not v1.ValueListItems.Contains(Value) Then v1.ValueListItems.Add(Value) End If End If
I tried using two overloads that Contains have. e.g. v1.ValueListItems.Contains(New Infragistics.Win.ValueListItem("value")) but still of no use. Could it be a bug ?
Thanks in advance.
-Swe2.
This will not work because Contains checks for an object on the list. It doesn't check properties off those objects. In other words, the ValueListItems collection contains ValueListItems and your Value is probably not a ValueListItem, it's a DataValue of a ValueListItem. So this will never return true, since the list will never contain an object that is not a ValueListItem.
Cast v1 into an IValueList and you can use the GetText method to find an item on the list with a given DataValue.
That worked. Thanks Mike.
If any have a similar problem. Here is the code.
(DirectCast(v1, Infragistics.Win.IValueList).GetText("value", Nothing) Is Nothing) Then
is the condition to check for.
Thanks!
If you declare an integer and set it to -1 and pass it in as the second param, then you can simply check if it's still -1 after you call GetText. I think that might be more efficient.