您好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