Fixed problem with ToolStrip items and PropertyBinding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q2hyaXMgV2Fsa2Vy?=

    Fixed problem with ToolStrip items and PropertyBinding

    PropertyBinding can be a great way to save user settings, but there is a
    problem with using PropertyBinding on ToolStrip items. I've found a solution
    to the problem and am sharing it here since I couldn't find a solution
    anywhere on the web.

    To recreate the problem:
    Add a ToolStrip to a form. Add a TextBox to the ToolStrip. PropertyBind
    the Text property of the TextBox (to do this, view the properties of the
    TextBox, go to ApplicationSett ings, on PropertyBinding , click the ... A list
    of properties will show up. Next to the Text Property click the down arrow,
    then click new. Type in TextData as the Name. Click OK, then Click OK again.

    You will now see under PropertyBinding that the Text property is bound (You
    can also tell this by the new little icon next to the Text property)

    Run the app, enter in some text, close the app, then restart it. It should
    have the text you entered but it doesn't. That's the problem.

    Why does it do this? When you bind the property VS creates the entry in the
    Settings.settin gs file, and creates the code to load the setting. What it
    doesn't do is create the code to save the setting.

    To add this code, go to the designer code (Have to click the Show All files
    button to get to it) In the Dispose method, after the If statement, put in
    the following code.

    My.Settings.Tex tData = ToolStripTextBo x1.Text

    Now, when you start the app, enter data, close the app and then restart, the
    text you entered will still be there.
Working...