我想DataGridView在编辑时在单元格周围绘制一个红色边框.
我设法在所选单元格周围绘制一个红色边框,而不是使用此代码编辑它:
private void Form1_Load(object sender, EventArgs e)
{
this.Width = 650;
this.Height = 250;
dataGridView1.Left = 5;
dataGridView1.Top = 5;
dataGridView1.Width = 600;
dataGridView1.Height = 175;
DataTable dt = new DataTable("Test Table");
dt.Columns.Add("Column 1");
dt.Columns.Add("Column 2");
dt.Columns.Add("Column 3");
dt.Columns.Add("Column 4");
dt.Columns.Add("Column 5");
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dt.Rows.Add(dt.NewRow());
dataGridView1.DataSource = dt;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.MultiSelect = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
dataGridView1.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.dataGridView1_CellPainting);
dataGridView1.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.dataGridView1_EditingControlShowing);
}
private void dataGridView1_CellPainting(object …Run Code Online (Sandbox Code Playgroud) 我有一个DataGridView和我在它的RowPostPaint事件期间在每行的第一个单元格上绘制TreeView样式的虚线.当第一个单元格(即a DataGridViewTextBoxCell)处于编辑模式时,不绘制线条.如何处理编辑控件的绘画?标准编辑控件没有Paint事件,如果我可以避免这样做,我不想创建新类型的单元格.
我有一个Windows窗体数据网格视图,其中行具有不同的背景颜色.
问题是,背景颜色在排序后消失(单击行标题),所有行再次变为白色(默认颜色).这个问题可能是什么原因?