Reputation: 926
I have a DataGridView for which I want to create an event handler for double clicks on individual cells. I'm trying to add a Windows.Forms.DataGridViewCellEventHandler to the DataGridView.DoubleClick event, but it will only accept a System.EventHandler. A simple type cast doesn't seem to work:
this.song_grid.DoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.cell_doubleclick);
Could someone please tell me the best way to get my DataGridView to accept a DataGridViewCellEventHandler? Thanks in advance.
Upvotes: 0
Views: 2518
Reputation: 236218
These events are different and they need different signature of event handlers. You can't add DataGridViewCellEventHandler
to simple EventHandler
. What you can do is call some method inside handlers of these events:
private void grid_DoubleClick(object sender, EventArgs e)
{
DoSomething();
}
private void grid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
DoSomething();
}
private void DoSomething()
{
// your code here
}
I assume you have subscribed both event handlers:
grid.DoubleClick += new System.EventHandler(grid_DoubleClick);
grid.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(grid_CellDoubleClick);
Upvotes: 1