I'm trying to call datagridview cell event method from an another button.
DataGridView Cell Double Click Method
private void ListDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
ListDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
DataGridViewRow row = this.ListDataGridView.Rows[e.RowIndex];
comboBox2.Text = row.Cells[1].Value.ToString();
}
}
This is Button where I'm calling this method
private void button6_Click(object sender, EventArgs e)
{
ListDataGridView_CellDoubleClick(sender, e);
}
Error I'm receiving
Error 3 The type or namespace name 'DataGridViewCellEventHandler' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 46 DataGridViewApplication
What I did:
I changed EventArgs to DataGridViewCellEventArgs.
private void button6_Click(object sender, DataGridViewCellEventArgs e)
{
ListDataGridView_CellDoubleClick(sender, e);
}
Now I'm receiving Error:
this.button6.Click += new System.EventHandler(this.button6_Click);
Error 3 No overload for 'button6_Click' matches delegate 'System.EventHandler'
C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 35 DataGridViewApplication
Now I changed button event handler code to this
this.button6.Click += new System.DataGridViewCellEventHandler(this.button6_Click);
Still Receiving this error and stucked here
Error 3 No overload for 'button6_Click' matches delegate 'System.EventHandler'
Found a solution here: How to call a datagridview event with a click of a button?
private void button6_Click(object sender, EventArgs e)
{
ListDataGridView_CellDoubleClick(null, null);
}
but this is not working for me, it gives me an error.
Object Reference not set to an instance of an object.