Detect if any control in a form has changed
-
Hi, I have several controls in my form ( a tab form... that includes combos, edit boxes, grids, ...).... Is there a way to know if any of this control has changed, just to change the flag and save changes ? ( I know that I could go control by control .... but is there a more generic way ?). Thanks, greetings Braulio
-
Hi, I have several controls in my form ( a tab form... that includes combos, edit boxes, grids, ...).... Is there a way to know if any of this control has changed, just to change the flag and save changes ? ( I know that I could go control by control .... but is there a more generic way ?). Thanks, greetings Braulio
If I understand what you are doing, then just use events with event handlers. All components have events for changes and stuff, for example the TextBox has a TextChangedEvent. In your form you can just add it to listen for this event. Using properties panel on the form design just click the events button (little lightning bolt above the panel of properties) and get a list of events for the Textbox you have slected, look for TextChanged or TextChanging, and double click that field. It will add a new Event handler in your form code, and you can do what ever in that method. It is the exact same as a button1_Click( object sender, MouseEventArgs e ) that you most likely have probably used before. All otehr controls have events as well, ComoboBox.SelectedChanged I think as well.
-
If I understand what you are doing, then just use events with event handlers. All components have events for changes and stuff, for example the TextBox has a TextChangedEvent. In your form you can just add it to listen for this event. Using properties panel on the form design just click the events button (little lightning bolt above the panel of properties) and get a list of events for the Textbox you have slected, look for TextChanged or TextChanging, and double click that field. It will add a new Event handler in your form code, and you can do what ever in that method. It is the exact same as a button1_Click( object sender, MouseEventArgs e ) that you most likely have probably used before. All otehr controls have events as well, ComoboBox.SelectedChanged I think as well.
Furthermore, if you only care about whether a control changed, you can assign the same event handler to all the "change" events of the controls on the form. Then, if you need to do more, you could use the sender object to do extra things (besides just determining if a control changed). You would just need a generic event handler in the form: ControlChanged( object sender, EventArgs e ) "Shut up brain, or I'll stab you with a QTip!" - Homer Simpson