Reputation: 543
I have a datagridview in which one of the columns is a checkbox. I handle the CellContentClick event to update information everytime the user check or uncheck one of the checkboxes. It works great. My problem is that when I double click a checkbox CellContentClick is called and then CellContentDoubleClick after that. I want to annul the call for CellContentDoubleClick. Is there a way to do this?
Upvotes: 7
Views: 6879
Reputation: 3
Instead of annulling for CellContentDoubleClick you can wire CellContentClick and CellContentDoubleClick to a single method.
gridviewTreasures.CellContentClick += new DataGridViewCellEventHandler(gridviewTreasures_CellContentClick);
gridviewTreasures.CellContentDoubleClick += new DataGridViewCellEventHandler(gridviewTreasures_CellContentClick);
Upvotes: 0
Reputation: 69
How about this:
public class MyDataGridView : DataGridView
{
protected override void OnCellContentDoubleClick(DataGridViewCellEventArgs e)
{
base.OnCellContentClick(e);
}
}
Upvotes: 0
Reputation: 16393
You could create your own class which inherits from DataGridView and override the method which would raise the event so that it doesn't get raised.
public class MyDataGridView : DataGridView
{
protected override viod OnCellContentDoubleClick(
DataGridViewCellEventArgs e)
{
// by having no code here and not
// calling base.OnCellContentDoubleClick(e);
// you prevent the event being raised
}
}
Upvotes: 0
Reputation: 167
You can remove event handler from datagrid.
EventHandler eventHandler = new EventHandler(YourdataGridview_CellContentDoubleClick);
YourdataGridview.CellContentDoubleClick -= eventHandler;
Upvotes: 1