Get a DataGridView and some data for it
Let's suppose we have this pre-populated DataGridView (it really doesn't matter what is the data source):DataGridView with hidden cell values
Just handle the DataGridView.CellPainting event to identify the cell you want to customize.C# .NET
1 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
2 {
3 // We are interested in handling the values in the "Value" column only...
4 if (e.ColumnIndex == valueDataGridViewTextBoxColumn.Index)
5 {
6 int cellValue = 0;
7
8 if (e.Value != null && Int32.TryParse(e.Value.ToString(), out cellValue))
9 {
10 if (cellValue == 0)
11 {
12 e.CellStyle.ForeColor = e.CellStyle.BackColor;
13 e.CellStyle.SelectionForeColor = e.CellStyle.SelectionBackColor;
14 }
15 }
16 }
17 }