TextBox1_LostFocus

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

    #1

    TextBox1_LostFocus

    I save the data that's in textbox1 in it's lostfocus event. I find one
    problem. If someone types something in textbox1 then Closes the program
    it isn't saved. I tried:

    Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
    System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
    TextBox1_LostFo cus(Me, Nothing)
    End Sub

    but for some reason it doesn't work. Any ideas? Is there another event
    I could use to detect closing and make sure the save is done?
  • cfps.Christian

    #2
    Re: TextBox1_LostFo cus

    On Dec 5, 9:34 am, cj <c...@nospam.no spamwrote:
    I save the data that's in textbox1 in it's lostfocus event. I find one
    problem. If someone types something in textbox1 then Closes the program
    it isn't saved. I tried:
    >
    Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
    System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
    TextBox1_LostFo cus(Me, Nothing)
    End Sub
    >
    but for some reason it doesn't work. Any ideas? Is there another event
    I could use to detect closing and make sure the save is done?
    Why not just save on form close, or pop up a dialog that asks "Do you
    want to save?" on form close? If you're trying to prevent multiple
    saves just have a boolean set to true when the form is saved and in
    the form_unload event use "if not bSaved then Save()".

    Comment

    • cj

      #3
      Re: TextBox1_LostFo cus

      I need to save the textbox each time the textbox loses focus. In
      addition since it doesn't seem to loose focus when you jump directly to
      Xing out the form/program I need to ensure that it is saved when folks
      do that.

      cfps.Christian wrote:
      On Dec 5, 9:34 am, cj <c...@nospam.no spamwrote:
      >I save the data that's in textbox1 in it's lostfocus event. I find one
      >problem. If someone types something in textbox1 then Closes the program
      >it isn't saved. I tried:
      >>
      >Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
      >System.Windows .Forms.FormClos ingEventArgs) Handles Me.FormClosing
      > TextBox1_LostFo cus(Me, Nothing)
      >End Sub
      >>
      >but for some reason it doesn't work. Any ideas? Is there another event
      >I could use to detect closing and make sure the save is done?
      >
      Why not just save on form close, or pop up a dialog that asks "Do you
      want to save?" on form close? If you're trying to prevent multiple
      saves just have a boolean set to true when the form is saved and in
      the form_unload event use "if not bSaved then Save()".

      Comment

      • cfps.Christian

        #4
        Re: TextBox1_LostFo cus

        On Dec 5, 10:12 am, cj <c...@nospam.no spamwrote:
        I need to save the textbox each time the textbox loses focus. In
        addition since it doesn't seem to loose focus when you jump directly to
        Xing out the form/program I need to ensure that it is saved when folks
        do that.
        >
        cfps.Christian wrote:
        On Dec 5, 9:34 am, cj <c...@nospam.no spamwrote:
        I save the data that's in textbox1 in it's lostfocus event. I find one
        problem. If someone types something in textbox1 then Closes the program
        it isn't saved. I tried:
        >
        Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
        System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
        TextBox1_LostFo cus(Me, Nothing)
        End Sub
        >
        but for some reason it doesn't work. Any ideas? Is there another event
        I could use to detect closing and make sure the save is done?
        >
        Why not just save on form close, or pop up a dialog that asks "Do you
        want to save?" on form close? If you're trying to prevent multiple
        saves just have a boolean set to true when the form is saved and in
        the form_unload event use "if not bSaved then Save()".
        The form_closed/closing events should hit whenever you hit the "X"
        too. What I would do in that case is just set up a separate method
        for saving and place that method within the form closed/closing event
        and Textbox_lostfoc us rather than calling the event method. If you're
        still having problems with your form closing/closed events firing even
        with the "X" then there might be another problem.

        Comment

        • cj

          #5
          Re: TextBox1_LostFo cus

          got it. I changed to using textbox1_textch anged event instead of
          lost_focus. I was afraid it would cause problems because in my mind
          each keystroke into the box is a textchanged event. Frankly that might
          be but it works and that is what matters right now.

          cj wrote:
          I save the data that's in textbox1 in it's lostfocus event. I find one
          problem. If someone types something in textbox1 then Closes the program
          it isn't saved. I tried:
          >
          Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
          System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
          TextBox1_LostFo cus(Me, Nothing)
          End Sub
          >
          but for some reason it doesn't work. Any ideas? Is there another event
          I could use to detect closing and make sure the save is done?

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: TextBox1_LostFo cus

            cj,

            If your textbox is binded, then you have to use the endedit (endcurrentedit
            in VB2003), if it is not binded, then your way to call the method is just
            fine.

            I would try to avoid the textchange event, that is firing at every
            keystroke, have a look while debugging and set than a breakpoint on that.

            Cor

            Comment

            • cj

              #7
              Re: TextBox1_LostFo cus

              it's not bound and textchange works, which is what's important

              BUT...

              Do you know how to bind the textbox to the 17th column of the currently
              selected row in a datagridview? I would like to try that.



              Cor Ligthert[MVP] wrote:
              cj,
              >
              If your textbox is binded, then you have to use the endedit
              (endcurrentedit in VB2003), if it is not binded, then your way to call
              the method is just fine.
              >
              I would try to avoid the textchange event, that is firing at every
              keystroke, have a look while debugging and set than a breakpoint on that.
              >
              Cor

              Comment

              • Cor Ligthert[MVP]

                #8
                Re: TextBox1_LostFo cus

                cj,

                the DATAgridview is in fact build to bind to a datasource. The best for that
                is in my opinion the DataTable. Are you using that?

                At that moment you can use the bind to the textbox to the DataTable, what is
                very simple to do.

                Have a look at this very simple sample, there is a datagrid used however
                because it is using a datatable it is in fact exactly the same as with a
                datagridview



                (instead of the labels you have to use textboxes)

                Cor

                Comment

                Working...