I have a datagrid
, which is bound to a datatable
, each cell has a unique value, so no two cells have the same value.
I want to change the cell with the value 1 (int32) to the color green. Note, the value of 1 is dynamic, thats just an example, it could be between 1-90.
I have searched around, and most of the help gives you the value of either a cell based on its coordinates i.e. (4,2) or the selected cell. This isn't what I want, I want to change the color of a cell based on its value.
Is there a way to do this, for example in JavaScript i would simply assign each cell an id equivalent to its value and then something like $('#' + 1).css('background-color:green;')
(note: this might not be correct syntax, but you get the picture). Is there a way as simple as this or a standard way of doing this?
My datagrid
<DataGrid Name="grid" ItemsSource="{Binding}" Height="300" Width="900"
AutoGenerateColumns="True"
VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Center" VerticalAlignment="Top" RowHeight="40">
<DataGrid.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</DataGrid.ItemsPanel>
</DataGrid>
Table creation
DataSet dataSet = new DataSet("myDS");
DataTable numbersTable = new DataTable("Numbers");
numbersTable.Columns.Add("Number", typeof(Int32));
for (int i = 1; i < 91; i++)
{
numbersTable.Rows.Add(i);
}
dataSet.Tables.Add(numbersTable);
grid.DataContext = numbersTable.DefaultView;