Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Databinding: "BindingSource - field" syntax

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc Vangrieken - 09 Aug 2006 14:59 GMT
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?
Dave Sexton - 11 Aug 2006 03:05 GMT
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.

Signature

Dave Sexton

> Hi,
>
[quoted text clipped - 22 lines]
> why doesn't the "bindingsource -  field" syntax work for all
> properties?
Marc Vangrieken - 11 Aug 2006 10:43 GMT
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.

> Hi Marc,
>
[quoted text clipped - 34 lines]
> > why doesn't the "bindingsource -  field" syntax work for all
> > properties?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.