I want to know how to get the DataGridCell from DataGridCellInfo. Actually i have a some selected cells in datagrid, and SelectedCells property return DataGridCellInfo's collection, but i want to change the background of those cells at runtime too. so i need the datagrid cell.
kindly suggest me how to do so and also how to change the datagrid cell background color dynamically(through code) also.
Thanks
To anyone who got here from a search engine, expecting to find an answer to the title in the question, look here: https://stackoverflow.com/a/17066695/937093
Content:
public DataGridCell GetDataGridCell(DataGridCellInfo cellInfo)
{
var cellContent = cellInfo.Column.GetCellContent(cellInfo.Item);
if (cellContent != null)
return (DataGridCell) cellContent.Parent;
return null;
}
edit
if you upvote this answer please don't forget to upvote the original answer I linked as well!
To change the color of the cell dynamically this is the simplest way
cell.Background = new SolidColorBrush(Colors.Green);
and to get the datagrid cell, follow this link
WPF Datagrid: Programmatically editing a cell
Thanks to Natxo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With