DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Trapping if data has changed on a form.

  1. #1
    Radhika Nair Guest

    Trapping if data has changed on a form.

    I have a data entry form with several controls on it (textboxes, comboboxes,
    checkboxes and radio buttons). I also have a "Save" and "Cancel" button.

    If the user hits the "Cancel" button and he has changed data on the form
    then I would like to prompt him with a message asking him if he wants to
    discard the changed data.

    My question is: is there an easy way to trap if any data has changed on the
    form without having to write "onchange" events for every single control on
    the form?

    Any help is appreciated.
    Thanks,
    Radhika



  2. #2
    Guest

    Re: Trapping if data has changed on a form.


    Hi Radhika

    I have also come across this problem. As you would probably be aware, the
    form's Binding Context objects (of type "CurrencyManager") expose "ItemChanged"
    and "CurrentChanged" events, but these both seem to fire only once you move
    off the changed record - i.e. they are no help to you! The DataTable class
    exposes similar "changed" events, but these, also, would seem to fire only
    once you move off the changed record.

    Perhaps somebody else has some better news for you!

    Stephen

    "Radhika Nair" <radhikan@first-insight.com> wrote:
    >I have a data entry form with several controls on it (textboxes, comboboxes,
    >checkboxes and radio buttons). I also have a "Save" and "Cancel" button.
    >
    >If the user hits the "Cancel" button and he has changed data on the form
    >then I would like to prompt him with a message asking him if he wants to
    >discard the changed data.
    >
    >My question is: is there an easy way to trap if any data has changed on

    the
    >form without having to write "onchange" events for every single control

    on
    >the form?
    >
    >Any help is appreciated.
    >Thanks,
    >Radhika
    >
    >



  3. #3
    Laurie Paulin Guest

    Re: Trapping if data has changed on a form.

    You can call EndEdit in your routine which will fire the changed events and
    set the HasChanges property on the dataset.

    Laurie Paulin

    <vb.@127.0.0.1> wrote in message news:3cdb17cd$1@10.1.10.29...
    >
    > Hi Radhika
    >
    > I have also come across this problem. As you would probably be aware, the
    > form's Binding Context objects (of type "CurrencyManager") expose

    "ItemChanged"
    > and "CurrentChanged" events, but these both seem to fire only once you

    move
    > off the changed record - i.e. they are no help to you! The DataTable

    class
    > exposes similar "changed" events, but these, also, would seem to fire only
    > once you move off the changed record.
    >
    > Perhaps somebody else has some better news for you!
    >
    > Stephen
    >
    > "Radhika Nair" <radhikan@first-insight.com> wrote:
    > >I have a data entry form with several controls on it (textboxes,

    comboboxes,
    > >checkboxes and radio buttons). I also have a "Save" and "Cancel" button.
    > >
    > >If the user hits the "Cancel" button and he has changed data on the form
    > >then I would like to prompt him with a message asking him if he wants to
    > >discard the changed data.
    > >
    > >My question is: is there an easy way to trap if any data has changed on

    > the
    > >form without having to write "onchange" events for every single control

    > on
    > >the form?
    > >
    > >Any help is appreciated.
    > >Thanks,
    > >Radhika
    > >
    > >

    >




  4. #4
    Larry Serflaten Guest

    Re: Trapping if data has changed on a form.

    "Radhika Nair" <radhikan@first-insight.com> wrote
    >
    > My question is: is there an easy way to trap if any data has changed on the
    > form without having to write "onchange" events for every single control on
    > the form?


    Here is the lazy way....

    Private Sub Changed(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles TextBox1.TextChanged, _
    TextBox2.TextChanged, _
    RadioButton1.CheckedChanged, _
    RadioButton2.CheckedChanged, _
    CheckBox1.CheckedChanged, _
    CheckBox2.CheckedChanged
    Dirty = True
    End Sub

    If they make any changes to the listed controls, it will set the flag, but the flag will still be set
    if they change it back....

    LFS



  5. #5
    Radhika Nair Guest

    Re: Trapping if data has changed on a form.

    Thanks everyone for your responses.
    I did figure out a way of doing it that would make things easier, here is
    the code I wrote in my form:

    Private Sub OnChange(ByVal sender As Object, ByVal e As EventArgs)
    mbHasChanged = True
    End Sub

    ' this method loops through the controls collection and ties
    ' the controls that can be changed to the "OnChange" event handler defined
    above.
    Private Sub GenerateEventHandlers()
    Dim iCount As Int32
    For iCount = 0 To Me.Controls.Count - 1

    Select Case Me.Controls(iCount).GetType.FullName
    Case "System.Windows.Forms.TextBox"
    AddHandler Me.Controls(iCount).TextChanged, AddressOf
    OnChange

    Case "System.Windows.Forms.ComboBox"
    Dim oComboBox As System.Windows.Forms.ComboBox =
    Me.Controls(iCount)
    AddHandler oComboBox.SelectedIndexChanged, AddressOf
    OnChange

    Case "System.Windows.Forms.CheckBox"
    Dim oCheckBox As System.Windows.Forms.CheckBox =
    Me.Controls(iCount)
    AddHandler oCheckBox.CheckedChanged, AddressOf OnChange

    Case "System.Windows.Forms.RadioButton"
    Dim oRadioButton As System.Windows.Forms.RadioButton =
    Me.Controls(iCount)
    AddHandler oRadioButton.CheckedChanged, AddressOf OnChange

    Case "System.Windows.Forms.DateTimePicker"
    Dim oDateTimePicker As System.Windows.Forms.DateTimePicker
    AddHandler oDateTimePicker.ValueChanged, AddressOf OnChange
    End Select

    Next
    End Sub

    I call GenerateEventHandlers() in my form's onload event.This way I don't
    have to write event handlers for every single control on my form and it
    seems to work fine.
    Hope this helps !

    Thanks,
    Radhika




    "Radhika Nair" <radhikan@first-insight.com> wrote in message
    news:3cdb0ee2$1@10.1.10.29...
    > I have a data entry form with several controls on it (textboxes,

    comboboxes,
    > checkboxes and radio buttons). I also have a "Save" and "Cancel" button.
    >
    > If the user hits the "Cancel" button and he has changed data on the form
    > then I would like to prompt him with a message asking him if he wants to
    > discard the changed data.
    >
    > My question is: is there an easy way to trap if any data has changed on

    the
    > form without having to write "onchange" events for every single control on
    > the form?
    >
    > Any help is appreciated.
    > Thanks,
    > Radhika
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center