Reputation: 113
I need to add a new row to DataGridView on "MouseClick" event. I do it, but the row is also added when I click on existing cells. I have another handlers on "CellClick/CellEndEdit" events and "MouseClick" is also raised in common with them. How to avoid this? Please help to solve this problem.
Thanks.
CellEndEdit event:
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;
}
}
MousClick event:
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];
}
Upvotes: 0
Views: 942
Reputation: 6079
Instead of dataGridViewWorks_MouseClick you can use dataGridViewWorks_MouseDoubleClick for adding the rows its an good idea :)
Upvotes: 1