Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dirty form

Posted on 2008-06-09
8
Medium Priority
?
383 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:AWestEng
  • 5
  • 2
8 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 21745016
do not used databinding
0
 
LVL 1

Author Comment

by:AWestEng
ID: 21745290
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..
0
 
LVL 25

Expert Comment

by:apeter
ID: 21753455
There are separate events like "Enter" is fired when we navigate the Tabs. We can place proper conditions there to avoid data binding ?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:AWestEng
ID: 21837853
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
0
 
LVL 27

Accepted Solution

by:
planocz earned 2000 total points
ID: 21884492
This is a little easier to read....
And I added some code for you to test.
 
   Private Sub AddChangedHandler(ByVal ctlX As Control)
        For Each ctrl As Control In ctlX.Controls
            If ctrl.HasChildren Then
                AddChangedHandler(ctrl) ' recurse into another container
            Else
                Select Case TypeName(ctrl)
                    Case "CheckBox"
                        AddHandler CType(ctrl, CheckBox).Click, AddressOf Datachanged
                    Case "ComboBox"
                        AddHandler CType(ctrl, ComboBox).SelectedIndexChanged, AddressOf Datachanged
                    Case "TextBox"
                        AddHandler CType(ctrl, TextBox).TextChanged, AddressOf Datachanged
                    Case "RadioButton"
                        AddHandler CType(ctrl, RadioButton).Click, AddressOf Datachanged
                    Case "DomainUpDown"
                        AddHandler CType(ctrl, DomainUpDown).SelectedItemChanged, AddressOf Datachanged
                    Case "NumericUpDown"
                        AddHandler CType(ctrl, NumericUpDown).ValueChanged, AddressOf Datachanged
                    Case "TabControl"
                        AddHandler CType(ctrl, TabControl).Click, AddressOf Datachanged
                    Case "TabPage"
                        AddHandler CType(ctrl, TabPage).Click, AddressOf Datachanged
                        AddHandler CType(ctrl, TabPage).TabIndexChanged, AddressOf Datachanged
                End Select
            End If
        Next
    End Sub
   Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        m_blnDirty = False
    End Sub
   Private Sub Datachanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
     If Me.TabControl1.SelectedIndex >= 0 Then Exit Sub
     If m_blnSkipDataChange Or String.IsNullOrEmpty(m_EmployNr) Then
            m_blnDirty = False
        Else
            m_blnDirty = True
        End If
    End Sub

Open in new window

0
 
LVL 1

Author Comment

by:AWestEng
ID: 21891400
ok, I will check it and get back to you, thx :)
0
 
LVL 1

Author Comment

by:AWestEng
ID: 21937366
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?

0
 
LVL 1

Author Comment

by:AWestEng
ID: 21940198
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

0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question