Posted by: Xiaonan Ji | September 25, 2009

Be cautious when using ToolStrip and Data Binding

If you use ToolStrip on a form that has data binding usage, you need to be careful. Clicking any item on a ToolStrip control doesn’t remove your cursor from any control on the form. For example, you edit a textbox on the form and directly click save item on ToolStrip, you will find that your cursor stays in the textbox the whole way. Now the problem is, since the cursor is never moved out of the textbox, the textbox “thought” that it itself is in edit and the data binding underlying will not be triggered. If the underlying data binding is not triggered, you may not be able to save the latest change if you purely rely on data binding to update underlying business object or whatever.

When I came across this problem, I just happen to have a button always sitting on my form. Whenever I click something on the ToolStrip control, I manually set the button to get the focus. In that way, whatever controls that holding data that need to be updated will be updated via data binding mechanism. This is just a quick & easy solution but it works. Whatever method suits you, you need to be careful that ToolStrip control operation doesn’t crab the focus from the main form and thus data binding may not work (in the right timing) for you!

Until next time, happy coding!


Responses

  1. There’s good info here. I did a search on the topic and found most people will agree with your blog. Keep up the good work mate!

  2. I don’t know If I said it already but …Hey good stuff…keep up the good work! :) I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks,)

    A definite great read..Jim Bean

  3. what a great site and informative posts, I will add a backlink and bookmark your site. Keep up the good work! :)

  4. Generally I do not post on blogs, but I would like to say that this post really forced me to do so, Excellent post!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.