Reputation: 21
I have the Database,that contains a table like so :
id | Description| Rate | ...
-----+------------+----------+------
1 | Product1 | 200 | ...
2 | Product2 | 200 | ...
3 | Product1 | 200 | ...
... | ... | ... | ...
Now I need to hide the specific cell value i.e. Product1
as in column Description
It should be like empty value to be displayed on datagridview :
id | Description| Rate | ...
-----+------------+----------+------
1 | Product1 | 200 | ...
2 | Product2 | 200 | ...
3 | | 200 | ...
... | ... | ... | ...
Upvotes: 2
Views: 7763
Reputation: 7973
You can handle the DataGridView.CellPainting event to identify the cell you want to customize.
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
// We are interested in handling the values in the "Description" column only..
if (e.ColumnIndex == DescriptionDataGridViewTextBoxColumn.Index)
{
string description="something";
if (e.Value != null)
{
if (e.Value.ToString()==description)
{
e.CellStyle.ForeColor = e.CellStyle.BackColor;
e.CellStyle.SelectionForeColor = e.CellStyle.SelectionBackColor;
}
}
}
}
Upvotes: 4