简体   繁体   中英

Access a cell in DataGrid.SelectedItems

I need to read a string from each of the the first cells of SelectedItems of the DataGrid

foreach (var item in myDataGrid.SelectedItems)
{
    if (item[0].ToString().Contains("Buy"))
    {
        containsBuy = true;
    }

    if (item[0].ToString().Contains("Sell"))
    {
        containsSell = true;
    }
}

How can I cast myDataGrid.SelectedItems? It is IList and gives object. Is there any simple and similar way to do it as it is done for one selected row of a DataGrid:

var row = myDataGrid.SelectedItem as DataRowView;

Here I can easy access any cell - row[i].

Just change your foreach loop to:

foreach (DataRowView in myDataGrid.SelectedItems)
{
    //...
}

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