0

VB and VS 2019 - I have a forms application and have used My.Settings successfully to bind textboxes to settings. It worked as it should. I recently added a new form and My.Settings is not listed for data binding (instead I get "add project datasource"). Additionally, my previous bindings of textboxes to My.Settings cannot be edited as the DataBndings "text" line is grayed out. It does display the previous binding as "(MySettings) - Matl2_Name". I added my new settings to My.Settings. Dragging and dropping a setting onto a textbox results in "MySettingsBindingSource - PR1Name" and it doesn't save.

Any help is appreciated.

  • *not listed for data binding* - I'm not sure they ever are. Application Settings and Data Bindings are different things: https://i.stack.imgur.com/tf3jj.png – Caius Jard Jan 30 '21 at 19:17
  • @Caius Jard Open up Application Settings, see `PropertyBinding`, add one and then look in the Form's designer.cs file. The DataBinding is now also there, but of course grayed-out. – Jimi Jan 30 '21 at 20:27
  • @Jimi aside from a minor part where [it doesn't always seem to be for me](https://i.stack.imgur.com/If42k.png) I know what you mean, but my point is that application settings bindings and data bindings (to a datasource) are different things, and the OP appears to be trying to edit settings bindings via the data route.. ? – Caius Jard Jan 30 '21 at 21:42
  • @Caius Jard PropertyBinding creates a DataBinding in `Form.designer.cs`, as `Me.[Control].DataBindings.Add(new Binding(...))` and it's a proper Data binding. To a class object, `MySettings`. A DataBinding that it treated internally in a slightly different way, but listed along with the Control's DataBindings -- The OP is clearly trying to add the binding using the wrong selector in the PropertyGrid. – Jimi Jan 30 '21 at 21:52
  • I think you're not understanding the "from the windows forms designer perspective" I'm talking about.. I know how it's done under the hood, but the OP doesn't [care] so I'm not going to that level of navel fluff – Caius Jard Jan 30 '21 at 21:57

1 Answers1

1

Here's a step by step, do you get the same result?

  • A new form:

enter image description here

  • A textbox on it:

enter image description here

  • Properties for it - going to bind the Text to a new setting (under the (Application Settings) grid node, NOT the (Data Bindings) node)

enter image description here

  • Settings binder:

enter image description here

  • Values:

enter image description here

  • All done - bound to setting now (and of course you cannot also bind the same property to a data providing thing, so it's greyed out - but you're binding settings, not data)

enter image description here

  • And the control has the value in the settings:

enter image description here enter image description here

Caius Jard
  • 72,509
  • 5
  • 49
  • 80