Question : WinForm Binding to child on UserControl

Hello,

I have a custom user control that basically has a combobox on it.  ( i do some custom painting.)

I would like user of my control to beable to put this control on their form and bind to it like if it were a combobox.

Thus far I have been unsuccesful - I've manage to bind the datasource but I can't seem to add a databindings to the control.

So basically:
CustomComboBox ccb = new CustomComboBox();

ccb.DataSource = somDS;
ccb.tcbKeyway.DisplayMember = "someMemeber";

works fine. BUT

ccb.DataBindings.Add("Text",someObject, "someProperty");

does NOT work.

Thanks

MAC

Here is a simplified version of my control:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
public class CustomComboBox : UserControl
    {

        [Category("Data")]
        public ComboBox.ObjectCollection Items
        {
            get { return this.comboBox1.Items; }
        }

        public object SelectedItem
        {
            get { return this.comboBox1.SelectedItem; }
            set { this.comboBox1.SelectedItem = value; }
        }

        public override String Text
        {
            get { return this.comboBox1.Text; }
            set { this.comboBox1.Text = value; }
        }

        //[Category("Data")]
        //public new ControlBindingsCollection DataBindings
        //{
        //    get { return this.comboBox1.DataBindings; }
        //}

        //[Category("Data")]
        //public object DataSource
        //{
        //    get { return this.comboBox1.DataSource; }
        //    set { this.comboBox1.DataSource = value; }
        //}

        //private BindingContext bindingContext;

        //public override BindingContext BindingContext
        //{
        //    set
        //    {
        //        bindingContext = value;
        //        OnBindingContextChanged(EventArgs.Empty);
        //    }
        //    get
        //    {
        //        // check if a BindingContext has been assigned
        //        if (bindingContext != null)
        //            return bindingContext;

        //        // check if we have a parent
        //        if (Parent != null)
        //            return Parent.BindingContext;

        //        // otherwise return null
        //        return null;
        //    }
        //}

        //protected override void OnParentBindingContextChanged(EventArgs e)
        //{
        //    if (bindingContext == null)
        //        OnBindingContextChanged(EventArgs.Empty);
        //}

        //[Category("Data")]
        //public String DisplayMember
        //{
        //    get { return this.comboBox1.DisplayMember; }
        //    set { this.comboBox1.DisplayMember = value; }
        //}

        public event EventHandler SelectedValueChanged
        {
            add
            { this.comboBox1.SelectedValueChanged += value; }

            remove
            { this.comboBox1.SelectedValueChanged -= value; }
        }

        public object DataSource
        {
            get { return comboBox1.DataSource; }
            set { comboBox1.DataSource = value; }
        }

        public string DisplayMember
        {
            get { return comboBox1.DisplayMember; }
            set { comboBox1.DisplayMember = value; }
        }

        public string ValueMember
        {
            get { return comboBox1.ValueMember; }
            set { comboBox1.ValueMember = value; }
        }
}

Answer : WinForm Binding to child on UserControl


This link => http://atakala.com/browser/Item.aspx?user_id=amos&dict_id=65
shows an example of using "Text" property to databind. One thing is it says to handle the TextChanged / SelectedValueChanged events to update the datasource.
Random Solutions  
 
programming4us programming4us