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 Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

RAD with Visual Studio - data binding user controls to forms' data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Harald Bjor?y - 14 Oct 2004 13:04 GMT
Hi

I am trying to make it quicker to use VS.NET to make applications that
maintain data in datasets.

My goal is to use the designers to do all databinding.

My problem is that I haven't found any easy way to use the data from the
forms as the "RAD-data bound data" of the user controls.

Typically, I have a set of data that is related in some ways, and that is of
a nature that it makes sense to load all data into memory at the same time.

To avoid having too much code in the same file - and to enhance resuability,
I want to organize the different areas I want to maintain in different user
controls. These could be used in pop-up windows and/or tabs in a tab
control.

I hope I have just not "checked the right button" - but my "research" tells
me this is not the case...

Example:
------------
Teams -table
Coaches - table

Data set: FootballData - both tables - and relation between Teams.FK_Coach
and Coaches.ID_Coach

One editor for the Teams and one for the Coaches - the Teams need to link to
one coach.

Form level:
An instance of a typed dataset: footballData1
A data view for footballData1.Teams and one for footballData1.Coaches -
dvTeams and dvCoaches.
In addition: a data view for Coach-dropdown on teams page - dvTeamCoaches
(table: footballData1.Coaches)
Loaded on Form_Load - and saved when "btnSave" is clicked. (both tables)

Tab One:
Data grid focusing on dvCoaches

Tab two
Data grid focusing on dvTeams. This includes a drop-down which has
dvTeamCoaches as data source, bound to FK_Coach

Result
---------
When not using user controls - this works perfectly. Whenever I add or
change a coach, it is instantly reflected on the team page, and I get an
exception when I try to delete a coach that is in use.

When I put the content of the tabs (along with data views belonging to the
tab) into user controls - i get problems.

To easily design the user controls using the designers, I have to add the
data set also to the user controls. (or is there another way?).

This instantiates a new data set - not the one I am to use.

The controls exposes the data set through get/set. When the data is
assigned - the problems occur.

The databindings on the form is always done before the property is set - in
the InitializeComponent-method.

When the data is changed aftwards, the bindings are still tied to the empty
instance of the data.

If i "rebind" by "manually" do the binding, everything works - but this
breaks the "RAD"-thing - I have to create my own binding-method that unbinds
old data, then binds the individual control. So if I add or replace a
control, I have to reprogram the binding-code.

Is there a easier way to make this "automatic"?

Why didn't Microsoft separate the databinding from the rest of the
initialize-code - if they did, it would be possible to loop through all
controls - removing all bindings (even better: generated binding method
supports a flag for unbinding), and then calling the binding-code to rebind.

Regards,
Harald Bjor?y
Tony Santolaria - 21 Oct 2004 08:20 GMT
"Harald Bjorøy" <harald.bjoroy-at-ulriken-consulting.no> wrote in message news:<eu4xEYesEHA.376@TK2MSFTNGP09.phx.gbl>...
> Hi
>
[quoted text clipped - 80 lines]
> Regards,
> Harald Bjorøy

Hello Harald, we are using the same architecture as you and
encountered this same problem.

We resolve this not assigning the dataset because as you correctly say
it destroys the previous databinding.

You should do this instead:

dataSet1.Clear();
dataSet1.Merge(dataSet2);

being "dataSet2" the DataSet "set" to the usercontrols. If you do so
the "RAD" databinding you created will be maintained.

We have found the method "Merge" extremely useful and are using it in
more scenarios.

hope it helps, cheers
Harald Bjor?y - 22 Oct 2004 10:36 GMT
Thanx, this is the answer I was looking for - this will work.

The interface I am working towards is intact, and the RAD in the control is
not breaking.

I have been looking for this answer for a long time, I also noticed that the
same problem exists in VS2005.

Harald

>> If i "rebind" by "manually" do the binding, everything works - but this
>> breaks the "RAD"-thing - I have to create my own binding-method that
[quoted text clipped - 31 lines]
>
> hope it helps, cheers
Harald Bjor?y - 22 Oct 2004 11:58 GMT
Well, I was a little bit quick in answering that this was The Answer...

It certainly helps in many situations - especially when I do the binding to
a modal dialog box, when I am able to determine that editing is finished
(dialog closed). But without merging back the data, change on one tab is not
reflected instantly on the other tab.

A problem is that the whole data set is duplicated in all controls - this
may add up to be vast.

I'll try to remedy these problems by saving the reference to the original
data set, and merge back when the control loses focus.

"I still haven't found what I'm looking for"... - but this is the best
workaround this far.

Microsoft: What about splitting InitializeComponent() to
InitializeComponent() and InitializeDatabinding()? This way we are able to
re-bind when the parent changes the data source of the user control?

It seems the upcoming Connector of .Net 2.0 still carries this problem - it
doesn't help binding to the Connector - the real data binding seems to be to
the underlying data table, as do the DataView of today.

Regards

Harald Bjor?y,
Ulriken Consulting AS
Norway

> Hello Harald, we are using the same architecture as you and
> encountered this same problem.
[quoted text clipped - 14 lines]
>
> hope it helps, cheers
Tony Santolaria - 22 Oct 2004 18:53 GMT
Yes, you are right. The reason we are using this is because in our
scenario we don´t have the same DataTables used in different
"controls" so we are not facing this trouble.
However we noticed this when we got a little replication in a pair of
controls, it was fixed with a similar approach you proposed (using
delegates but it is not worth explaining it because is not a good
solution neither).

As you say this can get huge in case of using the same data in
different controls, in fact I am wondering if not will be better to
implement manually the solution you are proposing. I'm still learning
a lot about .NET so I hope I will find a better solution in the
future,

"Harald Bjorøy" <harald.bjoroy-at-ulriken-consulting.no> wrote in message news:<upI$KYCuEHA.224@TK2MSFTNGP15.phx.gbl>...
> Well, I was a little bit quick in answering that this was The Answer...
>
[quoted text clipped - 25 lines]
> Ulriken Consulting AS
> Norway

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.