我需要在“MouseClick”事件上向 DataGridView 添加一个新行。我这样做了,但是当我单击现有单元格时,也会添加该行。我在“CellClick/CellEndEdit”事件上有另一个处理程序,并且“MouseClick”也与它们共同引发。如何避免这种情况?请帮助解决这个问题。
谢谢。
CellEndEdit 事件:
private void dataGridViewWorks_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
FormSelectItem frm = new FormSelectItem(formMain);
switch (dataGridViewWorks.Columns[e.ColumnIndex].Name)
{
case "WorksWORKNAME":
//some functions
break;
case "WorksCATNR":
//some functions
break;
case "WorksQuantity":
//some functions
break;
default:
break;
}
}
鼠标点击事件:
private void dataGridViewWorks_MouseClick(object sender, MouseEventArgs e)
{
if (dataGridViewWorks.Rows.Count == 0)
{
dataGridViewWorks.Rows.Add();
return;
}
dataGridViewWorks.Rows.Insert(dataGridViewWorks.Rows.Count);
dataGridViewWorks.CurrentCell = dataGridViewWorks.Rows[dataGridViewWorks.Rows.Count - 1].Cells[1];
}