你好,我正在开发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:此代码可以找到正确的列和行,但无法进行着色。