Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

as I am not an experienced programmer, I have a doubt about how to declare an event on my code.

I have a dataGridView that has to activate a method each time a value in a column is changed.

I know the method to make it happens is this one below:

private void dgrid_CellValueChanged(object sender, ataGridViewCellEventArgs e)<br />
{ ... }



But, even after including this method in my class it doesn't work!

Do I have to do something else? Do I have to declare anything somewhere else ( I mean, something to call this method when the event happens )?

If yes, how do I do it and where do I do it?

Thanks in advance! :)
Posted
Updated 31-Oct-10 19:31pm
v2

Maybe this is what you need. Put it on the form Load event.

C#
this.dgrid.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgrid_CellValueChanged);
 
Share this answer
 
Comments
lucasgrohl 1-Nov-10 0:49am    
Thank you very much! That is exactly what I needed and now it is working fine =)
Yes, you have to subscribe to that event: subscribe to the event[^]

In your form's constructor, you could add,
dgrid.CellValueChanged += new DataGridViewCellEventHandler(dgrid_CellValueChanged);


Also, if you're using Visual Studio, in the Design View of your form/window, go to the Properties tab, switch to "Events" (instead of properties) and double click on the event you need. And all the wiring up of events will automatically be done for you.
 
Share this answer
 
Comments
lucasgrohl 1-Nov-10 0:51am    
Hum, I see that. Thank you very much for the advice. For sure this is gonna solve many of my problems! =)
la01 1-Nov-10 17:09pm    
Glad I could help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900