Programatically selecting an option by 'Value'

Hi,

Is it possible to programatically select an option within a list view by a value, rather than it's index e.g.

If I have a List of e.g People, with attributes FirstName and Age, (e..g Data :-
Dave 25
Fred 12
Bert 50)

 and set this as the item source to the list view, this displays fine on my form,
What  I wish to be able to to do is programatically select the item in the list that has an age of e.g 50, which would be Bert.

I can see how to select an item by it's index, but not by a value in the underlying data source (Ive used other controls, and they had a displaymember and a value member, whereby the items in the list can selected via the valuemember fields value)

can you please help?

Many thanks,
Nick

1 Reply

MK Muthu Kumaran Gnanavinayagam Syncfusion Team October 19, 2017 11:46 AM UTC

Hi Nick,   
   
We have checked the reported query “Need to programmatically select the list items based on the specified value” from our side. You can achieve your requirement by checking the specific value from underlying collection and adding them into SelectedItems property of SfListView. Please refer the below code example:  
   
Code Example[C#]:   
public MainPage()   
{   
  InitializeComponent();   
  for(int i=0; i< ViewModel.Items.Count;i++)   
  {   
    var item = ViewModel.Items[i] as Model;   
    if(item.Age == "50")   
      listView.SelectedItems.Add(item);   
  }   
}   
   
We have already included regarding this in our documentation and you can refer the same from the below link,   
   
   
For your assistance, we have attached the working sample link below.   
   
   
Please let us know if you require further assistance.   
   
Regards,   
G. Muthu Kumaran.   


Loader.
Up arrow icon