user990692
user990692

Reputation: 543

how to stop the double click event in a datagridview from being raised?

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

Answers (4)

PayotCraft
PayotCraft

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

R. Shilling
R. Shilling

Reputation: 69

How about this:

public class MyDataGridView : DataGridView
{
    protected override void OnCellContentDoubleClick(DataGridViewCellEventArgs e)
    {
        base.OnCellContentClick(e);
    }
}

Upvotes: 0

Trevor Pilley
Trevor Pilley

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
    }
}

See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.oncellcontentdoubleclick.aspx

Upvotes: 0

David Jazbec
David Jazbec

Reputation: 167

You can remove event handler from datagrid.

     EventHandler eventHandler = new EventHandler(YourdataGridview_CellContentDoubleClick);
     YourdataGridview.CellContentDoubleClick -= eventHandler; 

Upvotes: 1

Related Questions