2

我有一个数据库,它包含一个像这样的表:

 id  | Description|  Rate    | ...
-----+------------+----------+------
 1   |  Product1  |  200     | ...
 2   |  Product2  |  200     | ...
 3   |  Product1  |  200     | ...
 ... |  ...       |  ...     | ...

现在我需要隐藏特定的单元格值,即Product1列描述

它应该像在 datagridview 上显示的空值:

 id  | Description|  Rate    | ...
-----+------------+----------+------
 1   |  Product1  |  200     | ...
 2   |  Product2  |  200     | ...
 3   |            |  200     | ...
 ... |  ...       |  ...     | ...
4

1 回答 1

4

您可以处理 DataGridView.CellPainting 事件来识别要自定义的单元格。

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;
         }
     }
 }
}
于 2013-10-30T12:21:13.700 回答