Handlers for Form Changes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




I have a form with about 25-30 TextBoxes, ComboBoxes, etc; if the user does
not make any changes to the form I don't want to post a "Cancel Changes?"
dialog when they exit the form ... so this is what I'm doing to detect
changes:


// this gets called from the Form_Load event handler

private void SetFormStateChangeHandlers(Control parent) // on 1st
entry, "this" is passed to the method
{
foreach (Control control in parent.Controls)
{
if (control is TextBox || control is ComboBox)
{
control.TextChanged += new
EventHandler(controlStateChanged);
}

// handle container controls which might have child controls
if (control.Controls.Count > 0)
{
SetFormStateChangeHandlers(control);
}
}
}

// set the class-level var to be tested on form exit
void controlStateChanged(object sender, EventArgs e)
{
FormHasChanged = true;
}


This *does* work, but there is at least one shortcoming, which is that if
the user changes a control and then undoes the change, I'm not detecting
that ... also, I'm just wondering if there's a better, more straightforward
way of handling the issue ... any other ideas out there?

TIA
Liz



.



Relevant Pages

  • RE: Dynamic userform help - Data Validation
    ... control. ... No textboxes or comboboxes. ... Sub Textbox_Change ... textboxes and comboboxes. ...
    (microsoft.public.excel.programming)
  • Re: VB6 Q: why are all comboboxes highlighted after form load?
    ... portion accurately reflects whether the control has focus or not. ... in any of the comboboxes yet. ... highlighting set looks kinda strange too, so I set out to rectify ... the form load event completes, ...
    (microsoft.public.vb.controls)
  • RE: Combobox Data
    ... decided to tag all the comboboxes with the word "CliveList" to the Combobox ... For Each control As Control In Me.TabPage1.Controls ... what to load all the Column names of the dataset into the item list of the ... so should i loop through the form and add all comboboxes to a list ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Multiple Controls in a Dynamic UserForm
    ... ComboBoxes and wherever there's an "X" write the values of the first, ... I'm cycling through all the controls in the corresponding ... control and can't step out of it. ... FYI - I get an Object Variable Not Set Error. ...
    (microsoft.public.excel.programming)
  • EndCurrentEdit
    ... I have a Form bound to a dataset with various types of controls, ... I have added event handlers to each input control that calls EndCurrentEditon the BindingManagerBase. ... On the comboboxes I have used the selectedIndexChanged event, and on textboxes I have used the leave event. ...
    (microsoft.public.dotnet.framework.windowsforms)