Link to home
Start Free TrialLog in
Avatar of AWestEng
AWestEngFlag for Sweden

asked on

Dirty form

Hi I use these function to indicate I have a dirty form,

All works ok excepet that the DataBindong is triggering the events when I change the tab in my form

I have 3 tabs with controls on, and all are using DataBinding.

Here is the code:

Any tips how I can solve this.? (Maybe a something that is saying that DataDinding is updating so I can skip the dirty flag in that moment)

 
''' <summary>
    ''' Loop thru all controls and add a handler to the controls that needs to be watched
    ''' </summary>
    Private Sub AddChangedHandler(ByVal ctlX As Control)
        For Each ctrl As Control In ctlX.Controls
            Application.DoEvents()
            If TypeOf ctrl Is TextBox Then
                AddHandler CType(ctrl, TextBox).TextChanged, AddressOf Datachanged
            ElseIf TypeOf ctrl Is System.Windows.Forms.ComboBox Then
                AddHandler CType(ctrl, System.Windows.Forms.ComboBox).SelectedIndexChanged, AddressOf Datachanged
            ElseIf TypeOf ctrl Is RadioButton Then
                AddHandler CType(ctrl, RadioButton).Click, AddressOf Datachanged
            ElseIf TypeOf ctrl Is DomainUpDown Then
                AddHandler CType(ctrl, DomainUpDown).SelectedItemChanged, AddressOf Datachanged
            ElseIf TypeOf ctrl Is NumericUpDown Then
                AddHandler CType(ctrl, NumericUpDown).ValueChanged, AddressOf Datachanged
            ElseIf TypeOf ctrl Is CheckBox Then
                AddHandler CType(ctrl, CheckBox).Click, AddressOf Datachanged
            Else
                AddChangedHandler(ctrl)
            End If
        Next
    End Sub
 
    ''' <summary>
    ''' Data is changed on a control, set flag
    ''' </summary>
    Private Sub Datachanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If m_blnSkipDataChange Or String.IsNullOrEmpty(m_EmployNr) Then
            m_blnDirty = False
        Else
            m_blnDirty = True
        End If
    End Sub

Open in new window

Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

do not used databinding
Avatar of AWestEng

ASKER

funny.. ;)

Because of all the controls I use it's to easy for query faults, databinding solves that.  There are changes pretty often, controls are being added or removed, and if not databinding, I need to recreate the querys every time.and check so all the querys work.. (SELECT,DELETE,UPDATE) To much work..

And we are taking about a total of 80 controls +/- 10. So Databinding is the best solution for this applicaiton.

So no tips how to solve this with databinding..
There are separate events like "Enter" is fired when we navigate the Tabs. We can place proper conditions there to avoid data binding ?
I don't want to avoid the databinding, I just want to avoid setting the form to dirty if not the user has changed any values
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, I will check it and get back to you, thx :)
hmm if I have 2 tabs. and changes a value an the first tab page the forms gets dirty as it should.

 But if i then change tab to make a change on the next tab the form get set to not dirty.that is not correct.

 The form should be dirty if the the user has change any data undtil the user saves it or interact with a dialog that asks if the user wants to save the employe bofore the chnges is lost.

any tips?

Using this solved it


Thx for helping

    Private Sub TabControlEmployed_Selected(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControlEmployed.Selected
        m_skipDataChanges = False
    End Sub
 
    Private Sub TabControlEmployed_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControlEmployed.Selecting
        m_skipDataChanges = True
    End Sub

Open in new window