471,618 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,618 software developers and data experts.

how do I call dataGridView_RowEnter event from within buttonSave_ Click event?

dataGridView1.RowEnter += new
DataGridViewCellEventHandler(dataGridView1_RowEnte r);
private void buttonSave_Click(object sender, EventArgs e)
{
//how do I activate RowEnter event below to obtain the the CustomerID as
I did below??????? <----------------------
}

private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs
e)
{
Customer c = m_Customers[e.RowIndex];
MessageBox.Show(c.SID.ToString());
}
Thank you,
-hazz
Feb 8 '06 #1
2 2096
private void buttonSave_Click(object sender, EventArgs e) {

Customer c = (CustomerdataGridView1.SelectedRows[0].DataBoundItem;
or
Customer c =
(Customer)dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].DataBoundItem;
// and then get the CustomerID property from the Customer object.
}

"hazz" <ha**@sonic.net> wrote in message
news:eG*************@TK2MSFTNGP09.phx.gbl...
dataGridView1.RowEnter += new
DataGridViewCellEventHandler(dataGridView1_RowEnte r);
private void buttonSave_Click(object sender, EventArgs e)
{
//how do I activate RowEnter event below to obtain the the CustomerID as
I did below??????? <----------------------
}

private void dataGridView1_RowEnter(object sender,
DataGridViewCellEventArgs e)
{
Customer c = m_Customers[e.RowIndex];
MessageBox.Show(c.SID.ToString());
}
Thank you,
-hazz

Feb 8 '06 #2
You might consider writing a handy property:

private Customer SelectedCustomer
{
get
{
if (dataGridView1.SelectedRows.Count == 0)
{
return null;
}
else
{
return
(Customer)dataGridView1.SelectedRows[0].DataBoundItem;
}
}
}

which would make your code easier to read:

private void buttonSave_Click(object sender, EventArgs e)
{
Customer c = this.SelectedCustomer;
if (c != null)
{
... do something with the customer ...
}
}

Feb 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Roger | last post: by
reply views Thread by luca | last post: by
22 posts views Thread by Ricky W. Hunt | last post: by
4 posts views Thread by John Wels | last post: by
5 posts views Thread by Lostdante via DotNetMonster.com | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.