How to get the indexes of checked items

Hi!

I can't find any method to get the indexes of the checked items.

I need to know the index number of each element that is checked in the control.



For example in the above picture i need to get numbers 1,3,4

The other thing i tried is to manage it on the ItemChecked event like this:

private void lstAppNamePTT_ItemChecked(object sender, Syncfusion.WinForms.ListView.Events.ItemCheckedEventArgs e)
        {
            if(e.NewState == CheckState.Checked) {
                AppChecked.Add(e.ItemIndex);
            } else
            {
                AppChecked.Remove(e.ItemIndex);
            }
        }
Bit that doesn't give me a way to do it outside the event.

Any suggestions?

3 Replies 1 reply marked as answer

UN Unknown Syncfusion Team June 10, 2020 11:30 AM UTC

Hi Elias, 

Thanks for contacting Syncfusion support. 

We have checked your query “Need to know how to get the checked item indexes in SfListView ” and there is no direct support for your requirement. It can be achieved by checking the checked items with items in View of SfListVIew and getting their index value. Please refer the below code snippet for same. 

C#: 
ObservableCollection<int> selectedIndex = new ObservableCollection<int>(); 

            foreach (var allItems in sfListView1.View.Items) 
           
                foreach (var checkedItem in sfListView1.CheckedItems) 
               
                    if(allItems == checkedItem) 
                   
                        selectedIndex.Add(sfListView1.View.DisplayItems.IndexOf(allItems)); 
                   
               
           


Regards, 
Niranjan Kumar Gopalan 


Marked as answer

ES Elias Stassinos June 11, 2020 06:59 AM UTC

Thank You!


UN Unknown Syncfusion Team June 11, 2020 07:54 AM UTC

Hi Elias, 
 
Thanks for your update. 
 
We are glad to know that reported requirement has been achieved. We are happy to assist you always. 
 
Regards, 
Niranjan Kumar Gopalan 


Loader.
Up arrow icon