问题是通过单击datagridview复选框单元格来更改按钮的颜色,并通过单击相同的复选框来另外突出显示一个绘制的箭头。Datagridview复选框单元格更改按钮和绘制线的颜色
这正在与TaW的解决方案一起工作。感谢那。
private void dataGridView1_CellContentClick(object f_sender_dgv, DataGridViewCellEventArgs f_event_dgv)
{
DataGridView dataGridView1 = f_sender_dgv as DataGridView;
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
DataGridViewCell cb_1 = dataGridView1[2, 0];//
//DataGridViewCell cb_1 = dataGridView1[f_event_dgv.ColumnIndex , f_event_dgv.RowIndex];
if (cb_1 is DataGridViewCheckBoxCell)
{
bool c = (bool)(cb_1 as DataGridViewCheckBoxCell).Value;
button_gv_1.BackColor = c ? Color.Yellow : Color.Snow;
button_v_5.BackColor = c ? Color.Yellow : Color.Snow;
}
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g;
g = e.Graphics;
Pen myPen = new Pen(Color.Black);
myPen.Width = 1;
myPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
//g.DrawLine(myPen1, 400, 700, 1000, 100);//(X_start, Y_start, X_ende, Y_ende)
// test if data is loaded:
if (!(dataGridView1.RowCount > 0 && dataGridView1.ColumnCount > 2)) return;
//use the correct indices = [e.ColumnIndex, e.RowIndex]
DataGridViewCell cell = dataGridView1[2,0];
if (cell is DataGridViewCheckBoxCell && cell.Value != null)
{
bool c = (bool)(cell as DataGridViewCheckBoxCell).Value;
Pen myPen1 = c ? Pens.Yellow : Pens.Black;
g.DrawLine(myPen1, 400, 700, 1000, 100);//(X_start, Y_start, X_ende, Y_ende)
}
}
什么,如果现在点击复选框时发生了什么?你的代码是什么datagridview? – MaCron