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 / April 2007

Tip: Looking for answers? Try searching our database.

Cross-forms databinding - design time question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dmitry Nogin - 11 Apr 2007 12:36 GMT
Hi,
I'm going to show modal dialog which contains a lot of controls. My dataset
is placed on the parent form. How to databind dialog controls to parent
form's dataset at design time? Is it possible?

-- thanks
Bryan Phillips - 11 Apr 2007 14:49 GMT
Create a property on the dialog form to receive the value that you want
to bind to.   Then, pass in that value to the form just before you show
it.

In the dialog form, either bind the controls to the DataSet at design
time or in the form's load event handler.  I hope this helps.

Ex:

// sample form with a DataSet property
public class MyDialog : Form
{
    public DataSet DataSet
    {
        ...
    }
}

...

// in the parent form:
private void ShowModal()
{
    MyDialog dialog = new MyDialog();

    dialog.DataSet = (DataSet) this.dataGrid1.DataSource;

    dialog.ShowDialog(this);
}

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net

> Hi,
> I'm going to show modal dialog which contains a lot of controls. My dataset
> is placed on the parent form. How to databind dialog controls to parent
> form's dataset at design time? Is it possible?
>
>  -- thanks
Dmitry Nogin - 11 Apr 2007 15:37 GMT
Yes, that's it. But how can I "bind the controls to the DataSet at design
time"? DataSet is a dialog's runtime property, right? That one you defined
in the MyDialog bellow...

> Create a property on the dialog form to receive the value that you want to
> bind to.   Then, pass in that value to the form just before you show it.
[quoted text clipped - 38 lines]
>>
>>  -- thanks
Bryan Phillips - 11 Apr 2007 20:27 GMT
One more thing for design-time binding:

You will need a strongly-typed DataSet to do design-time binding.

If you bind at run-time with a regular DataSet, you will have to
reference columns using strings which will cause headaches later if you
have to change the structure of the data.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net

> Yes, that's it. But how can I "bind the controls to the DataSet at design
> time"? DataSet is a dialog's runtime property, right? That one you defined
[quoted text clipped - 42 lines]
> >>
> >>  -- thanks
mrlucmorin - 12 Apr 2007 02:18 GMT
> Hi,
> I'm going to show modal dialog which contains a lot of controls. My dataset
> is placed on the parent form. How to databind dialog controls to parent
> form's dataset at design time? Is it possible?
>
>  -- thanks

Hi,

What I found as a solution is to place a new instance of the dataset on the
second form to allow you to benefit from design-time databinding.

Then, I add a constructor to the second form that accepts an instance of the
DataSet as parameter. Within the constructor you call something like:

dataSetOnForm2.Merge(dataSetFromForm1ConstructorParameter);

Though it may not be the most efficient way, I haven't found anything yet
that allows me to retain the design time functionalities.

If you need to return the changes from Form2, simply add a property that
will return the changes in the DataSet:

return dataSetOnForm2.GetChanges();

You can then merge this back into the Form1 dataset.

Hope this helps.

Luc

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.