Databinding: "BindingSource - field" syntax

  • Thread starter Thread starter Marc Vangrieken
  • Start date Start date
M

Marc Vangrieken

Hi,

I have a question regarding databinding via the Visual Studio 2005 form
designer. What I wanted to do is not a very good practice, it was just
"quick and dirty" in really small application. I had a WinForms
form with a typed dataset and a lot of controls bound to it via
BindingSources. Because a lot of these fields are optional, and I
wanted to clean the form up, I added a little button invoking a second
(modal) form containing those fields. The latter only contained a
BindingSource that got hooked up to the typed dataset on the main form
(by passing a reference at creation) in runtime. (I passed the entire
dataset because i needed a few tables with reference data).

Knowing that the schema of the dataset will never change again I just
wanted to bind the controls on the second form to the bindingsource in
design time. Of course, the designer can't provide me with
DisplayMembers, etc...

I found that it was possible to manually set the DataBindings property
for Text and Tag using the " bindingsource - field" syntax, the
correct code is generated. For other fields, e.g. SelectedValue in a
combobox, this is not possible via the properties window.

I am curious now, is this a bug in VS2005 or is this supported? If so,
why doesn't the "bindingsource - field" syntax work for all
properties?
 
Hi Marc,

You can bind the SelectedValue property of a ComboBox, and any other property for that matter, to a data source on the Form using
the Properties window in VS.NET 2005. What exactly are you having trouble with?

The common properties are marked with BindableAttribute(true) in code so they appear in the Properties window under the Data
category and the "(DataBindings)" heading. You can click the ellipses button next to "(Advanced)" to view the remaining properties
of the Control to which you are binding.
 
Hi,

That's correct indeed; the problem was that my bindingssource was not
connected to any datasource in design-time, so it doesn't show up in
the pick list. I wanted to connect the bindingsource to a dataset in
runtime, but I didn't want to bind all the controls to the
bindingsource by code.

Then I tried to edit the properties manually (not using the pick list),
and it was possible to manually set a binding (via the properties
windows) by typing "BindingSource - Field". In the generated code, code
was added for the binding. This only was possible for the common
properties (BindableAttribute(true)), not for the other ones (because
you can't manually edit the "binding comboxbox" in that screen.

So I just wondered if this way of working is supported or not, also
because if did not find any information on it... Although I know the
drawbacks of this approach, I find myself wanting to do it in simple
cases.

Today i figured out how to do it for all properties, first add a
dataset in design time, connect to the bindingsource, bind all the
properties you want and then remove the dataset again, but leave the
bindingsources.

So actually, the "problem" is solved, but thanks anyway.
 
Back
Top