こんにちは、私はWindowsフォームアプリケーションで作業していますが、問題があります。私たちはデータグリッドビューを使用しています。もし1つ以上の列が空であれば、それを強調表示したいと思います。私は理由を知りませんが、私のコードは動作しません。ここに私のコード;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
を形成することdoesntの仕事:( – Berkin