正如标题所说,DataGridView.DefaultCellStyle.SelectionBackColor not working smoothly
的意思是我创建表单并在内部加载事件中使用以下代码:
using (FbConnection con = new FbConnection(M.Baza.connectionString))
{
con.Open();
using (FbDataAdapter da = new FbDataAdapter("SELECT BRDOK, DATUM, ZA_MAGACINID AS MAGACIN, KOMENTAR1 AS ODREDISTE, PRETVOREN_U_BRDOK_KOMERCIJALNO AS VEZA, FLAG FROM DOKUMENT WHERE VRDOK = 999", con))
{
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Columns["BRDOK"].Width = 100;
dataGridView1.Columns["DATUM"].Width = 100;
dataGridView1.Columns["MAGACIN"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridView1.Columns["ODREDISTE"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridView1.Columns["VEZA"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
dataGridView1.Columns["FLAG"].Visible = false;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Transparent;
}
}
您可以看到我设置了dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Transparent;
当我启动表单时,我得到了
如您所见,第一行是白色。当我单击另一行并返回它时,它变为透明的,但首次出现是有问题的。该怎么办?
答案 0 :(得分:0)
我会避免使用“透明”作为您的颜色。尝试使用与网格本身相同的颜色:
dataGridView1.DefaultCellStyle.SelectionBackColor = dataGridView1.DefaultCellStyle.BackColor;
dataGridView1.DefaultCellStyle.SelectionForeColor = dataGridView1.DefaultCellStyle.ForeColor;