简体   繁体   中英

How to find an item from SelectedItems back in the main DataGrid.Items

I have an IList which is a copy of SelectedItems within a DataGrid.

If I iterate through this IList and select an item. I am using a simple 'for()' statement to do this, instead of a 'foreach()' as I need the index.

How can then use this item to find the same item in the main items?

Let's say the third item out of SelectedItems is the one I'm trying to find, how do I find this in DataGrid.Items?

Same way as you find it in list

for(int i = 0; i < myDataGrid.Items.Count; i++)
{
    if (((IList)myDataGrid.Items[i]) == myitem)
    {
      //Found Item
    }
}

Make sure that the both are same instance, else it will always return false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM