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
> 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