Click here to Skip to main content
15,897,151 members

Response to: I need an event that fires when a row has been modified

Revision 1
Hi Friend,
I believe that you can use the method that I am gonna provide you here in VB too, since I am not working with VB and this one is in C#, so pretty off the language of your interest but perfect in the way what you require to do. I hope you will be able to translate it in VB since .NET is quite Language independent :-)

Let us look at my solution, that I am giving you here after 1 hr of mind boggling work (only for you my friend)

See, the codes first, then I will explain it below :
The first thing is to define a global boolean
C#
bool changed = false;


The next step is to define this inside Form Load Event:
C#
foreach (Control mycon in this.Controls.OfType<textbox>())
{
   mycon.TextChanged   +=  new EventHandler(mycon_TextChanged);
}
</textbox>


As you can see here, I simply looped through all the textbox controls (well you can do for other controls also) and added a single event handler function to all of them. Now let us see what's inside this function. so here's the code :

C#
public void mycon_TextChanged(object sender, EventArgs e)
{
    changed = true;
    foreach(Control mycon as this.Controls.OfType<textbox>())
    {
        mycon.TextChanged -= mycon_TextChanged;
    }
}
</textbox>

Now here I simply set that boolean to true and after that I removed all the event handlers since I guess they are no longer required as the close button now for sure will have to ask for saving the changes (Change has been made).

Now You simply need to test this boolean, and if it is set, implement your codes to save this new data :-) Cheers

Regards
Tushar Srivastava :-)
Posted 21-Sep-12 10:37am by Er. Tushar Srivastava.
Tags: ,