Reputation: 1552
So I'm wondering if someone can give me a good idea how to do something. I have a tabControl in my application - I load up a page - TabPage1 - with about 25-30 fields. On loading all the data - i run a loop to save each control value to .tag. I also have a function called isDirty() that basically checks each control's ctr.tag.tostring <> ctr.text. I'm having a hard time figuring out how to build a quick handler to check all controls on the form. I tried using TagPage1.Validating, however that doesn't do anything.
my isDirty() function looks like this...
Private Function isDirty() As Boolean
isDirty = False
For Each ctr As Control In TabPage1.Controls
If TypeOf ctr Is TextBox And ctr.Enabled = True Then
If ctr.Tag.ToString <> ctr.Text Then
isDirty = True
End If
End If
'more if statements for comboboxes and such
Next
End Function
I'm hoping to be able to plug this function in somewhere and do a CALL on it something like
if isDirty() then
MsgBox "You have made a change to this form"
End if
Do i have to call this on each control's selection changed?
Upvotes: 0
Views: 206
Reputation: 3141
There are 2 approaches
Exit For
, after isDirty = True
.bool changed
. Controls like textbox
, combobox
, radiobutton
, checkbox
, etc.. mostly have their change event handlers, if the change is made set changed
to True
.Upvotes: 1