Bind event to Datagridview - where's list of events?

R

Rich

Migrating from VB.Net to C# - I am sure that I can perform all the same
actions in C#. Right now working with a Datagridview control. The only
list of events I can see in C# for the Datagridview is in the Designer
window/Datagridview Properties under the Flash symbol. The event I am
looking for is the RowEnter event, which I do not see under this list of
events under the Flash symbol. So I wrote this event as follows except it is
not firing - how do I hook it up to the Datagridview?

private void dgrv1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
Console.WriteLine(e.RowIndex.ToString());
}

I use this event in VB.Net all the time. So I am sure it is available in C#
- maybe under a different event name?

Thanks,
Rich
 
R

Rich

Thank you. I used your method and it works. But how do I get this event to
show up in the property grid? That would be easier for hooking up the
events. I know the Datagridview controls has dozens (if not hundreds) of
events. But I only see about a dozen of them listed in the property grid.
How to get them to show up in the property grid?

Nicholas Paldino said:
Rich,

It's available, but the way that you hook up events in C# is different from VB.NET.

You have to actually make the assignment:

dgrv1.RowEnter += dgrv1_RowEnter;

Which is shorthand for:

dgrv1.RowEnter += new DataGridViewCellEventHandler(dgrv1_RowEnter);

The VB.NET compiler does some magic and hides most of this for you.

The designer surface hides it for you in C# by placing the line above in the InitializeComponent method for your class which is using the data grid view. I would use the property grid to add the event. It certainly is there. If you want the designer to create the method for you, just double click on the row:




--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Migrating from VB.Net to C# - I am sure that I can perform all the same
actions in C#. Right now working with a Datagridview control. The only
list of events I can see in C# for the Datagridview is in the Designer
window/Datagridview Properties under the Flash symbol. The event I am
looking for is the RowEnter event, which I do not see under this list of
events under the Flash symbol. So I wrote this event as follows except it is
not firing - how do I hook it up to the Datagridview?

private void dgrv1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
Console.WriteLine(e.RowIndex.ToString());
}

I use this event in VB.Net all the time. So I am sure it is available in C#
- maybe under a different event name?

Thanks,
Rich
 
R

Rich

Nevermind. I figured it out. I added the event assignment to the Initialize
components section. The next time I restarted the project - that event
showed up in the Property grid of the Datagridview control.

Rich said:
Thank you. I used your method and it works. But how do I get this event to
show up in the property grid? That would be easier for hooking up the
events. I know the Datagridview controls has dozens (if not hundreds) of
events. But I only see about a dozen of them listed in the property grid.
How to get them to show up in the property grid?

Nicholas Paldino said:
Rich,

It's available, but the way that you hook up events in C# is different from VB.NET.

You have to actually make the assignment:

dgrv1.RowEnter += dgrv1_RowEnter;

Which is shorthand for:

dgrv1.RowEnter += new DataGridViewCellEventHandler(dgrv1_RowEnter);

The VB.NET compiler does some magic and hides most of this for you.

The designer surface hides it for you in C# by placing the line above in the InitializeComponent method for your class which is using the data grid view. I would use the property grid to add the event. It certainly is there. If you want the designer to create the method for you, just double click on the row:




--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Migrating from VB.Net to C# - I am sure that I can perform all the same
actions in C#. Right now working with a Datagridview control. The only
list of events I can see in C# for the Datagridview is in the Designer
window/Datagridview Properties under the Flash symbol. The event I am
looking for is the RowEnter event, which I do not see under this list of
events under the Flash symbol. So I wrote this event as follows except it is
not firing - how do I hook it up to the Datagridview?

private void dgrv1_RowEnter(object sender, DataGridViewCellEventArgs e)
{
Console.WriteLine(e.RowIndex.ToString());
}

I use this event in VB.Net all the time. So I am sure it is available in C#
- maybe under a different event name?

Thanks,
Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top