I need to do the following with a DataGrid. E.g.

Col A       Col B
1           A           
2           B
3           C
4           D

For instance where Col A = 3. I then want to change the background cell.Background = some color where row 3 intersects Col B. I would be passing in the value for Col A and column name dynamically. I am returning the cell values from a DataTable where the DataGrid is bound to a defaultview of the DataTable. Col A is the unique key.

有帮助吗?

解决方案 2

Found a solution with a single line of code to pragmatically set the current cell based on the items and column index for anyone else who may be looking for a solution to this as well.

In the XAML ensure the SelectionUnit is set to cell. Then:

dg.CurrentCell = new DataGridCellInfo(dg.Items[0],dg.Columns[0]);

其他提示

if you wanna change your cell style - use the cell style and Style.DataTrigger. you just have to make sure that the data you need is anywhere in the DataRow.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top