0

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?

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
BobSki
  • 1,531
  • 2
  • 25
  • 61
  • The NET provider and helper objects will do *all* that for you. And if they didnt, I'd take an OOP approach and have a class (Cust, Order, Eno...whatever) whch tracked changes, or an ORM. – Ňɏssa Pøngjǣrdenlarp Nov 17 '16 at 20:13

1 Answers1

1

There are 2 approaches

  1. When most of the controls do not have change event handler, your approach seems to be correct. By the way, in your above code you missed Exit For, after isDirty = True.
  2. When most of the controls have changed event handler implemented(this will be the case if in your design you have data models/objects), rather than checking changes in a loop, I would prefer to check when the change is made. I mean to say declare a form level variable bool changed. Controls like textbox, combobox, radiobutton, checkbox, etc.. mostly have their change event handlers, if the change is made set changed to True.
Mukul Varshney
  • 3,131
  • 1
  • 12
  • 19
  • I understand i was just trying ti find a way to do it in one event handler, kinda like _validating evemt i think i might try that – BobSki Nov 18 '16 at 05:08