Problem with Textbox and File-Save

G

Guest

I'm developing a WinForms app and have a slight problem that I hope someone
can help me with. There are a series of textboxes that the user can enter
information into. The text in these boxes is only copied into the data model
when the textbox's LostFocus event is fired. This has worked well so far.

But I've just noticed that if the user enters some text into a textbox and
then goes up to File-Save (on the parent form) that the newly entered text is
not saved. This is obviously because this event is not causing the LostFocus
event to be fired.

I think there might be several ways to resolve this issue but am seeking
advice from those of you who have encountered the same problem before.
 
G

Guest

I was about to respond that I could not get this to work as you described...
but then I tried it another way and it did end up the way you said, always
interesting the difference between using MessageBox.Show() and
Console.WriteLine() when it comes to timing.

Best way I’d suggest, would be to do a this.Focus() within your MenuItem’s
Click handler, just before you do any of your actual saving work. This would
take focus away from the current TextBox and force it to update via your
existing methods.

Brendan
 
G

Guest

Brendan,

This is one of those "Why didn't I think of that?!?" moments!

Simple and effective and does EXACTLY what I want!

Thank you so much and have a great weekend!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top