Change the cell background colour to red when the data…
Listening to the DataGridView.CellFormatting Event, based on the data, update the cell style in runtime.
1. Add Listener:
this.dataGridViewForLogs.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridViewForLogs_CellFormatting);
2. The hanlder:
private void dataGridViewForLogs_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.Value == null) { return; } if (dataGridViewForLogs.Columns[e.ColumnIndex].Name.Equals("result")) { String logResult = e.Value.ToString(); if (logResult != null && logResult.Contains("FAIL")) { e.CellStyle.BackColor = Color.Red; e.CellStyle.ForeColor = Color.White; e.CellStyle.SelectionBackColor = Color.Navy; return; } } e.CellStyle.BackColor = Color.White; }
links:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx
C#: Using DataGridView <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.