Catch changes made by user

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vovan

    #1

    Catch changes made by user

    I have set of controls (Textboxes, checkboxes etc) along with the Grid on
    Windows Form.
    I use BindingSource to populate both Grid and the set of Controls. User
    selects the record in the grid and all controls are populated with data from
    the selected row.
    The grid is going to be read only. Textboxes, checkboxes are going to be
    read/write.
    What event and how do I need to use to catch any change in any of the
    textboxes? I tried to use TextBox_TextCha nged, but it fires during initial
    population and every time I change the active row in the grid. How can I
    distinguish between changes made by the program and changes made by the
    user?
    I need to set the flag blnIsThereAnyCh ange = True when user changes the
    contents of the textbox, and use the value of that flag in some procedures.

    Thank you
    vovan



  • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

    #2
    RE: Catch changes made by user

    vovan,

    Since you are using bound controls, any changes in the textboxes will be
    reflected in the underlying datatable.

    So you could use datatable.HasCh anges to see if any changes have been made.

    Kerry Moorman


    "vovan" wrote:
    I have set of controls (Textboxes, checkboxes etc) along with the Grid on
    Windows Form.
    I use BindingSource to populate both Grid and the set of Controls. User
    selects the record in the grid and all controls are populated with data from
    the selected row.
    The grid is going to be read only. Textboxes, checkboxes are going to be
    read/write.
    What event and how do I need to use to catch any change in any of the
    textboxes? I tried to use TextBox_TextCha nged, but it fires during initial
    population and every time I change the active row in the grid. How can I
    distinguish between changes made by the program and changes made by the
    user?
    I need to set the flag blnIsThereAnyCh ange = True when user changes the
    contents of the textbox, and use the value of that flag in some procedures.
    >
    Thank you
    vovan
    >
    >
    >
    >

    Comment

    • =?Utf-8?B?Q2hhcmxpZQ==?=

      #3
      RE: Catch changes made by user

      Use the Enter and Leave events of the TextBoxes and CheckBoxes to Add and
      Remove the Change handlers for those controls.

      Here is an example for a checkbox--

      Private Sub CheckBox1_Check edEnter(ByVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles CheckBox1.Enter
      AddHandler CheckBox1.Check StateChanged, _
      AddressOf CheckBox1_Check edChanged
      End Sub

      Private Sub CheckBox1_Leave (ByVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles CheckBox1.Leave
      RemoveHandler CheckBox1.Check StateChanged, _
      AddressOf CheckBox1_Check edChanged
      End Sub

      Private Sub CheckBox1_Check edChanged( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArg s)
      'add code here
      End Sub

      When the user changes the check of a checkbox, the enter event will fire
      first and add the checkchange event hander. Then the checkstatechang ed event
      will fire and read the new value for the checkbox.

      If you have a lot of textbox and checkbox controls, you could, (from within
      the form_load event), consolidate your code by pointing all of the Enter
      addhandler statements for one control type to a single code block, and
      likewise for Leave. If you do that, of course, the "sender" object is the
      control that fired Enter or Leave, and you should use cast the objectly
      appropriately.. .
      directcast(send er, Textbox)

      When you want to detect whether a change has been made for any control, you
      have to come up with a monitoring system that captures original values after
      the controls are populated. If the user makes changes, comare the current
      value to the original value, and set the flag for the control accordingly.
      If the user re-sets to the original value, your change flag should be reset
      to false for that entry. This also gives you an opportunity to have a Cancel
      Changes button that restores all changes to the current record to their
      current unchanged values. You may be able to use the grid row as your
      original values reference, but sometimes, by design, a grid will not show all
      values that are shown in the controls on the form.


      "vovan" wrote:
      I have set of controls (Textboxes, checkboxes etc) along with the Grid on
      Windows Form.
      I use BindingSource to populate both Grid and the set of Controls. User
      selects the record in the grid and all controls are populated with data from
      the selected row.
      The grid is going to be read only. Textboxes, checkboxes are going to be
      read/write.
      What event and how do I need to use to catch any change in any of the
      textboxes? I tried to use TextBox_TextCha nged, but it fires during initial
      population and every time I change the active row in the grid. How can I
      distinguish between changes made by the program and changes made by the
      user?
      I need to set the flag blnIsThereAnyCh ange = True when user changes the
      contents of the textbox, and use the value of that flag in some procedures.
      >
      Thank you
      vovan
      >
      >
      >
      >

      Comment

      • vovan

        #4
        Re: Catch changes made by user

        Thank you Kerry
        HasChanges is a method of Dataset object. When I make any change in the
        bound controls and do not move to another record, probably changes are not
        moved yet from controls to the Dataset and when I'm calling HasChanges it
        returns FALSE.
        First of all it seem inconvenient for me to move to another row to check if
        there were changes. The second issue is how do I check if changes occured, I
        mean what event of what object I need to use to find it out.
        My plans were:
        I'm staying on the particular row in the grid, if I make any change in any
        bound control, I set somehow the flag responsible for changes to true, at
        the same time I change the visible properties of buttons "AddNew", "Update",
        "Cancel", Delete". If user is trying to move to another row I display a
        message box asking if she wants to save changes. Changes are saved for each
        row separately.
        I was going to use TextChanged event for textboxes to reset the flag, but as
        I said before it fires not only from user actions.

        vovan

        "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
        news:C36391E9-D492-439D-AB47-93E1E35C2D2A@mi crosoft.com...
        vovan,
        >
        Since you are using bound controls, any changes in the textboxes will be
        reflected in the underlying datatable.
        >
        So you could use datatable.HasCh anges to see if any changes have been
        made.
        >
        Kerry Moorman
        >
        >
        "vovan" wrote:
        >
        >I have set of controls (Textboxes, checkboxes etc) along with the Grid on
        >Windows Form.
        >I use BindingSource to populate both Grid and the set of Controls. User
        >selects the record in the grid and all controls are populated with data
        >from
        >the selected row.
        >The grid is going to be read only. Textboxes, checkboxes are going to be
        >read/write.
        >What event and how do I need to use to catch any change in any of the
        >textboxes? I tried to use TextBox_TextCha nged, but it fires during
        >initial
        >population and every time I change the active row in the grid. How can I
        >distinguish between changes made by the program and changes made by the
        >user?
        >I need to set the flag blnIsThereAnyCh ange = True when user changes the
        >contents of the textbox, and use the value of that flag in some
        >procedures.
        >>
        >Thank you
        >vovan
        >>
        >>
        >>
        >>

        Comment

        • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

          #5
          Re: Catch changes made by user

          vovan,

          Perhaps you could use the datatable's RowChanging, RowChanged,
          ColumnChanging or ColumnChanged events.

          Personally, I would avoid trying to use textbox events to determine if the
          data is changing. I have rarely seen that work out well.

          Kerry Moorman


          "vovan" wrote:
          Thank you Kerry
          HasChanges is a method of Dataset object. When I make any change in the
          bound controls and do not move to another record, probably changes are not
          moved yet from controls to the Dataset and when I'm calling HasChanges it
          returns FALSE.
          First of all it seem inconvenient for me to move to another row to check if
          there were changes. The second issue is how do I check if changes occured, I
          mean what event of what object I need to use to find it out.
          My plans were:
          I'm staying on the particular row in the grid, if I make any change in any
          bound control, I set somehow the flag responsible for changes to true, at
          the same time I change the visible properties of buttons "AddNew", "Update",
          "Cancel", Delete". If user is trying to move to another row I display a
          message box asking if she wants to save changes. Changes are saved for each
          row separately.
          I was going to use TextChanged event for textboxes to reset the flag, but as
          I said before it fires not only from user actions.
          >
          vovan
          >
          "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
          news:C36391E9-D492-439D-AB47-93E1E35C2D2A@mi crosoft.com...
          vovan,

          Since you are using bound controls, any changes in the textboxes will be
          reflected in the underlying datatable.

          So you could use datatable.HasCh anges to see if any changes have been
          made.

          Kerry Moorman


          "vovan" wrote:
          I have set of controls (Textboxes, checkboxes etc) along with the Grid on
          Windows Form.
          I use BindingSource to populate both Grid and the set of Controls. User
          selects the record in the grid and all controls are populated with data
          from
          the selected row.
          The grid is going to be read only. Textboxes, checkboxes are going to be
          read/write.
          What event and how do I need to use to catch any change in any of the
          textboxes? I tried to use TextBox_TextCha nged, but it fires during
          initial
          population and every time I change the active row in the grid. How can I
          distinguish between changes made by the program and changes made by the
          user?
          I need to set the flag blnIsThereAnyCh ange = True when user changes the
          contents of the textbox, and use the value of that flag in some
          procedures.
          >
          Thank you
          vovan
          >
          >
          >
          >
          >
          >
          >

          Comment

          • =?Utf-8?B?RGVubmlz?=

            #6
            Re: Catch changes made by user

            I agree that detecting changes with text box events rarely works out as the
            programmer intends. What I would suggest is that you have a class containing
            all the record data then when the row changes, check in the row changed event
            if the text boxes contain the same info...if not, update the previous record
            then reset the class properties to the new row data.

            Hope you can get some ideas from this.
            --
            Dennis in Houston


            "vovan" wrote:
            Thank you Kerry
            HasChanges is a method of Dataset object. When I make any change in the
            bound controls and do not move to another record, probably changes are not
            moved yet from controls to the Dataset and when I'm calling HasChanges it
            returns FALSE.
            First of all it seem inconvenient for me to move to another row to check if
            there were changes. The second issue is how do I check if changes occured, I
            mean what event of what object I need to use to find it out.
            My plans were:
            I'm staying on the particular row in the grid, if I make any change in any
            bound control, I set somehow the flag responsible for changes to true, at
            the same time I change the visible properties of buttons "AddNew", "Update",
            "Cancel", Delete". If user is trying to move to another row I display a
            message box asking if she wants to save changes. Changes are saved for each
            row separately.
            I was going to use TextChanged event for textboxes to reset the flag, but as
            I said before it fires not only from user actions.
            >
            vovan
            >
            "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
            news:C36391E9-D492-439D-AB47-93E1E35C2D2A@mi crosoft.com...
            vovan,

            Since you are using bound controls, any changes in the textboxes will be
            reflected in the underlying datatable.

            So you could use datatable.HasCh anges to see if any changes have been
            made.

            Kerry Moorman


            "vovan" wrote:
            I have set of controls (Textboxes, checkboxes etc) along with the Grid on
            Windows Form.
            I use BindingSource to populate both Grid and the set of Controls. User
            selects the record in the grid and all controls are populated with data
            from
            the selected row.
            The grid is going to be read only. Textboxes, checkboxes are going to be
            read/write.
            What event and how do I need to use to catch any change in any of the
            textboxes? I tried to use TextBox_TextCha nged, but it fires during
            initial
            population and every time I change the active row in the grid. How can I
            distinguish between changes made by the program and changes made by the
            user?
            I need to set the flag blnIsThereAnyCh ange = True when user changes the
            contents of the textbox, and use the value of that flag in some
            procedures.
            >
            Thank you
            vovan
            >
            >
            >
            >
            >
            >
            >

            Comment

            Working...