【发布时间】:2016-12-02 09:29:13
【问题描述】:
您好,我正在使用 Windows 窗体应用程序,但我遇到了问题。我们正在使用数据网格视图,如果一行或多列为空,我想突出显示它。我不知道为什么,但我的代码不起作用。这是我的代码;
public Form1()
{
InitializeComponent();
var dtCombined = PopulateCombinedDatatable();
dataGridView.DataSource = dtCombined;
HighlateIfEmpty();
}
public string[] FindFilePath()
{
//OPERATIONS
}
public DataTable PopulateCombinedDatatable()
{
//MY OPERATIONS
}
public void HighlateIfEmpty()
{
foreach (DataGridViewRow row in dataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if ((string)cell.Value == string.Empty)
{
cell.Style.BackColor = Color.BlueViolet;
cell.Style.SelectionBackColor = Color.Aquamarine;
row.DefaultCellStyle.SelectionBackColor = Color.BlueViolet;
row.DefaultCellStyle.ForeColor = Color.Yellow;
row.DefaultCellStyle.BackColor = Color.Aquamarine;
}
}
}
}
谢谢...
PS : 此代码找到正确的列和行但不绘制它
【问题讨论】:
-
请稍后调用该函数,可能是FormLoad或FormShown事件
-
它不起作用:(
标签: c# datagridview