Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Implement Complex Binding on a non-visual Component

$
0
0

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

  1. Set BindingSource1 to a custom object, some List<Offices>
    (it has the great feature of getting the list from service, custom, etc)
  2. Set MyDialog1.DataSource = BindingDataSource1
  3. Set MyDialog1.DataMember = ""

At run-time

  1. 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,


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>