473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

TextBox1_LostFocus

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?
Dec 5 '07 #1
7 1715
On Dec 5, 9:34 am, cj <c...@nospam.nospamwrote:
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()".
Dec 5 '07 #2
cj
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.nospamwrote:
>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()".
Dec 5 '07 #3
On Dec 5, 10:12 am, cj <c...@nospam.nospamwrote:
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.nospamwrote:
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()".
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.
Dec 5 '07 #4
cj
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 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_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?
Dec 5 '07 #5
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

Dec 5 '07 #6
cj
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
Dec 5 '07 #7
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

Dec 5 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave Cousineau | last post by:
im using VB.NET and i am creating an array of textboxes i want to handle a LostFocus event for any of the textboxes that i might create (at runtime), so that when the user enters a value into...
6
by: Patrick De Ridder | last post by:
How do I connect to an event being thrown when a field has lost focus? Could you please give a code example? -- Patrick De Ridder ngmail@freeler.nl
2
by: W. Adam | last post by:
I have a form which displays info. On top of it there is a text box for input box which lets you put number from 1 thu 10. My question is "What do i need to do in order not to let the user go past...
3
by: Hal Gibson | last post by:
Because of a legacy (originally DOS) Sub Procedure "AlphaInput" that is called in thousands of places in our code, I need to be able to set a variable, "KeyedString",to the value of TextBox.Text...
4
by: dudzcom | last post by:
hi, this is the first time i've posted to this board, though i have been a devoted lurker for some time i have been working in vb.net and run into a couple problems that seem to require solutions...
12
by: Gene Hubert | last post by:
How do I make a TextBox behave like the address bar in IE? That is... If focus is not on the tb, select all text if clicking on the tb or tabbing into the tb. Clicking again deselects the text...
8
by: cj | last post by:
I asked this question a couple of days ago but am just now looking at it again. I used to use the textbox gotfoucs event to have all the text in the textbox selected when it gotfocus. That...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
16
by: jamesnkk | last post by:
I am trying to validate a QTY entry in a form , if user did not enter anything or 0 , I will prompt for a message and the cursor return to the QTY entry column. I have tried Lost Focus in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.