I have 3 things that I need to implement a complex data binding between them. I have
- a form class that has a property 'List<Office> Offices'.
- a nonvisual component (MyDialog) that displays the form using an Execute() method
- a main form (form) that contains a BindingSource Object (BindingSource1) and the non-visual object (MyDialog1)
From a developer design point of view...I want to
at Design-Time
- Set BindingSource1 to a custom object, some List<Offices>
(it has the great feature of getting the list from service, custom, etc) - Set MyDialog1.DataSource = BindingDataSource1
- Set MyDialog1.DataMember = ""
At run-time
- Call MyDialog1.Execute()
obviously I will want the underlying dialog box's "Offices" property to be bound to the MyDialog1's Datasource property which is referencing the BindingDataSource1 component which is referencing a List<Office>.
How do I implement MyDialog Datasource and Data Member properties? And how do I bind the Datasource value to the underlying hidden form object's "Offices" property?
Hopefully, I'm clear in what I want...just having a heck of a time with MyDialog implementing Datasource/Datamember and the fact that MyDialog class is a non-visual component. It's not a control. Also, the Datasource property at design-time is greyed out (not letting me associate it to my form's BindingSource1). Below is a part of MyDialog component
[TypeConverter("System.windows.Forms.Design.DataSourceConverter")]
[Category("Data")]
[DefaultValue("")]
public Object DataSource
{
get { return _dataSource; }
set
{
if (_dataSource != value)
{
_dataSource = value;
tryDataBinding();
}
}
}
[Category("Data")]
[Editor("System.Windows.Forms.Design.DataMemberListEditor,System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
[DefaultValue("")]
public string DataMember
{
get { return _dataMember; }
set
{
if (_dataMember != value)
{
_dataMember = value;
tryDataBinding();
}
}
}
private void tryDataBinding()
{
Debug.Assert(_form != null);
_form.DataBindings.Add("Offices", DataSource, DataMember);
}Regards,