I have a datagrid that outputs 90 rows after being bound to a datatable. The rows values are the 1-90 ascending.
What I want to achieve:
If the number is found in an array/range/list of numbers then highlight it green.
I have managed to get it to highlight the cell based on 1 value, but I want to highlight several cells if they are found in the range.
<DataGrid Name="grid" ItemsSource="{Binding}" Height="300" Width="900"
AutoGenerateColumns="False"
VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Center" VerticalAlignment="Top" RowHeight="40">
<DataGrid.Resources>
<Style x:Key="BackgroundColourStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="1">
<Setter Property="Background" Value="LightGreen" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=Number}"
ElementStyle="{StaticResource BackgroundColourStyle}" MinWidth="40">
</DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</DataGrid.ItemsPanel>
</DataGrid>
you can see I have a trigger property of the value 1. This works fine, but as above, how do I change this so if a cell is in the range set in c# in backend then highlight it green.
binding to datatable:
calledGrid.DataContext = calledNumbers.DefaultView;
The actual making of the datatable:
DataSet dataSet = new DataSet("myDS");
this.bingoCalls(dataSet);
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);
Thanks for any help guys. If you need any more info or I have been to vague or unclear about anything please do ask and i will do my best to respond ASAP. Also please excuse any ignorance I may have, I am very new to wpf. I will do my best.