TextBox1_LostFocus

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

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_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
TextBox1_LostFocus(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?
 
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_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
TextBox1_LostFocus(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()".
 
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.
 
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.

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_lostfocus 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.
 
got it. I changed to using textbox1_textchanged 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,

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
 
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.
 
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

http://www.vb-tips.com/CurrencyManager.aspx

(instead of the labels you have to use textboxes)

Cor
 
Back
Top