I have a DataGrid
WPF control and I want to get a specific DataGridCell
. I know the row and column indices. How can I do this?
I need the DataGridCell
because I have to have access to its Content. So if I have (for example) a column of DataGridTextColum
, my Content will be a TextBlock
object.
Here is the code I used:
This assumes that the DataGrid has already been loaded (executed its own Loaded handler).
You can use code similar to this to select a cell:
I can't see a way to update the contents of a specific cell directly, so in order to update the content of a specific cell I would do the following
You can simply use this extension method-
and you can get a cell of a DataGrid by an existing row and column id:
grid.ScrollIntoView
is the key to make this work in case DataGrid is virtualized and required cell is not in view currently.Check this link for details - Get WPF DataGrid row and cell