How come function V is not called when i press button2, and how can i overcome this without the code being in an actual datagridview event ?
Thanks
Anthony
public partial class Form1 : Form
{
public delegate void Call(object sender, DataGridViewCellEventArgs o);
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Call op = new Call(V);
}
public void V(object sender, DataGridViewCellEventArgs o)
{
int rowIndex = o.RowIndex;
if (rowIndex >= 0)
{
string Email = dataGridView1.Rows[o.RowIndex].Cells["DateEntered"].Value.ToString();
textBox2.Text = Email;
}
}
}
}
Subhendu DePosted Dec 13, 2010, 6:15 AM
you can populate DataGridViewCellEventArgs using following ways
1) In the DataGridView Events
2) Passing valuse when initializing
You cannot get valid rowIndex and columnIndex from button_click event. Only way to pass values through constructor like following
I am showing you how to call function V using delegate, not how to get DataGridViewCellEventArgs outside dataGridview events because this is impossible.
public delegate void _delegate(object sender, DataGridViewCellEventArgs o);
public partial class Form1 : Form
{
_delegate Call;
public Form1()
{
InitializeComponent();
Call = V;
}
private void button2_Click(object sender, EventArgs e)
{
Call(this,new DataGridViewCellEventArgs(2,2)); // 2,2 IS SAMPLE VALUE
}
public void V(object sender, DataGridViewCellEventArgs o)
{
int rowIndex = o.RowIndex;
if (rowIndex >= 0)
{
string Email = dataGridView1.Rows[o.RowIndex].Cells["DateEntered"].Value.ToString();
textBox2.Text = Email;
}
}
}
}
Sam HobbsPosted Dec 14, 2010, 12:08 AM
Anthony ClarkePosted Dec 13, 2010, 6:42 AM
thanks Subhendu