Select cell value from DataGrid.ItemsSource

I have a WPF DataGrid whose ItemsSource property is bound to a DataTable.DefaultView. In VB.NET I could get the value of the first field of the first row with: myValue = DataGrid.ItemsSource(i)(0)

Assume myValue is a string and i is an integer. The DataGrid is already populated.

In C#, that doesn’t work obviously. I tried: myValue = DataGrid.ItemsSource[i][0]; but I keep getting the error ”Cannot apply indexing with [] to an expression of type’IEnumerable’”

I’m trying to programmatically set the selected row in the grid to a row where the value of a specific column matches a value elsewhere, but I am trying to use the code above to pull the value to evaluate. “i” will be an iterator which will be used to set the SelectedIndex property.

Any ideas?

submitted by /u/Mastersord
[link] [comments]

Leave a Reply