Waterside
asked on
Linq .Where in VB.net
How do I use Linq to search for an object in a list control.
The list holds objects that have tKey and tValue properties so I'd like to write something like..
myListControl.SelectedItem = myListControl.Items.Where( Item.tValu e.Equals(" FindMe"))
Thanks
The list holds objects that have tKey and tValue properties so I'd like to write something like..
myListControl.SelectedItem
Thanks
ASKER
I thought that was the way to go myself but got..
Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.Com pilerServi ces.NewLat eBinding.L ateGet' is not defined.
..at Item.tValue
Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.Com
..at Item.tValue
For asome crazy reason, you need to Cast it to Object:
Giannis
myListControl.SelectedItem = myListControl.Items.Cast(Of Object).Where(Function(x) x.tValuex.tValue.Equals("FindYou")).FirstOrDefault
Giannis
Hi Waterside;
What is the Type of your "list control"?
You state the following, "The list holds objects that have tKey and tValue properties", so are you using a KeyValuePair Type? If so what is the DataType of TKey and TValue of the KeyValuePair(Of Tkey, TValue)?
Can you post the actual line of code and the code surrounding it so we can try to make some sense for the error.
What is the Type of your "list control"?
You state the following, "The list holds objects that have tKey and tValue properties", so are you using a KeyValuePair Type? If so what is the DataType of TKey and TValue of the KeyValuePair(Of Tkey, TValue)?
Can you post the actual line of code and the code surrounding it so we can try to make some sense for the error.
ASKER
The control is a ListPicker.
The ItemsSource is List(of KeyValuePair(of Integer, String)
I need to set the SelectedItem KVP object for a given key or value.
The ItemsSource is List(of KeyValuePair(of Integer, String)
I need to set the SelectedItem KVP object for a given key or value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that's got it :)
Excellent, glad it worked out for you.
Try the following:
Open in new window
Giannis