Form close changes notification and databinding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TonFrere
    New Member
    • Nov 2007
    • 14

    Form close changes notification and databinding

    Hello,
    I'm simply trying to keep track of changes on a windows form as users modify control values. I created a boolean variable called IsDirty and want it set to true whenever the user changes something.

    The problem is: where to set IsDirty to true?

    If I raise the event on "TextChange d" event of a control (let say a textbox), it is set to true whenever the user changes current record.

    I also tried to raise it on "Validating " event but then, as soon as I enter a control and leave it, IsDirty is set to true even if the user haven't made any changes.

    This was very easy with the DatagridView control since I could add the code to the OnCellEndEdit event.

    I bet there's a much easyier way to look for a "row dirtiness" directly on the form (maybe through the bindingsource?) .

    Any advice?
    Thanks a lot,
    Justin
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What controls do you need it for besides textbox?
    "TextChange d" seemed like a good place for it?

    Comment

    • TonFrere
      New Member
      • Nov 2007
      • 14

      #3
      Common controls: Combobox, CheckBoxes etc. Is it ok to look it from the control side or should I find a way to check if the bindingsource or dataset are changed?

      I'm a little embarrassed to be stock on something that seems so obvious.

      Justin

      Originally posted by Plater
      What controls do you need it for besides textbox?
      "TextChange d" seemed like a good place for it?

      Comment

      • TonFrere
        New Member
        • Nov 2007
        • 14

        #4
        I can't use "TextChange d" because this would be raised each time the user changes record.

        Windows Forms, C#, Visual Studio 2005.

        Still need help.
        Thanks!

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Originally posted by TonFrere
          I can't use "TextChange d" because this would be raised each time the user changes record.
          Don't you WANT that to happen so you can set isDirty=true?

          Comment

          • TonFrere
            New Member
            • Nov 2007
            • 14

            #6
            Sorry, I'll try to describe a little more.

            I want IsDirty set to true whenever a user changes a value on the form. This is to track changes (and to advice the user if he leaves without saving).

            If I set IsDirty to True in the "TextChange d" event, it happens whenever a user make changes (which is good) but also, whenever a user move between records using the Binding Navigator move next, move previous etc. buttons (which is not good). This happens because the actual value of the control changes from a record to the other (which is perfectly logic) but I can't find an event that would be raised only when a user physically changes the contain of a control.

            I also tried adding the event in the "validated" event. But then, as soon as a control gets the focus, IsDirty is set to true (even if the user doesn't make any changes or the control gets the focus "accidentally") .

            In other words, I want to track only user simply "have made changes"...

            I have a feeling I'm doing this the wrong way.

            What do you think?
            Justin

            Comment

            • TonFrere
              New Member
              • Nov 2007
              • 14

              #7
              I think I found the perfect combo to make this work:

              - For each control TextChange (or equivalent for other controls) I set IsDirty to True. (Capturing users changes)

              - On BindingSource CurrentChanged, I set IsDirty to False. (Because it is set to true when controls are filled with db values.)

              - On form OnActivated event, I set IsDirty to false (this way I don't get it set to true after the initial binding is done).

              The only trouble with this is that users will not be notified if they have made changes to a record, then move to another, and finally close the form without changing anything. I might as well save changes between record navigation.

              It works though... this seems a lot of trouble for such a trivial feature.

              Anybody has a better idea?

              And is there be a way of adding the "set isdirty to true" feature on all controls on my form (when form load or whatever)? This way, I would make sure that new controls added to the form would have the same feature (Should I override all controls type classes and add the feature to them... is this good or bad pratice?)

              Thanks,
              Justin

              Comment

              Working...