I am currently working on a C# WPF datagrid. I have a DataGrid which has auto generated columns and the code connects to an SQLite Database and creates a dataset and then this dataset is set as the DataGrid ItemsSource.
Below is the code with the XAML of the DataGrid
<DataGrid AutoGenerateColumns="True"
Margin="12,71,12,32"
Name="tblLog"
ColumnWidth="*"
CanUserResizeRows="False"
AreRowDetailsFrozen="False"
CanUserAddRows="True"
CanUserDeleteRows="True"
IsReadOnly="True"
MouseDoubleClick="tblLog_MouseDoubleClick">
</DataGrid>
And below is the code to set the ItemsSource for the DataGrid
try
{
DataSet ds = new DataSet();
SQLiteDataAdapter da = new SQLiteDataAdapter(query, db.conn);
da.Fill(ds);
//tblGrid.AutoGenerateColumns = true;
tblGrid.ItemsSource = ds.Tables[0].DefaultView;
}
catch (SQLiteException ex)
{
MessageBox.Show("Unable to retrieve logins from database.\n\n" + ex.Message + "\n\nError Code: " + ex.ErrorCode);
}
The columns that are shown in the database (auto generated) are ID, date, time, status. What I need to be able to do is if the value in a row of the status column equals Error change the background colour of that row.
I assume I need to add some sort of styling tags and DataTriggers within the DataGrid tags but not sure what I need. Anything I have tried to the code that sets the ItemsSource displays an error saying that the Source needs to be empty before adding the ItemsSource.
Thanks for any help you can provide.