您好im正在使用Windows窗体应用程序,但我有一个问题。我们正在使用数据网格视图,如果一行或多列为空,我想突出显示它。我不知道为什么,但我的代码不起作用。这里是我的代码;DataGridView行颜色不会更改
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事件 – TaW
它不工作:( – Berkin