Thanks Jeffrey.
There's a perfectly good reason to do this (to me at least). In my case I
combo-box was being set properly. It's not that I wanted to synchronize the
do two-way binding to an object. So when the Combo-box.SelectedValue
""Jeffrey Tan[MSFT]"" wrote:
> Hi BBM,
>
> Based on my understanding, you want to keep a combobox and textbox with the
> winform databinding synchronizely.
>
> Actually, you misunderstanded the concept of databinding. For winform
> simple databinding, a control's property is bound to a datasource's
> datamember(Such as a property). While 2 controls bound to the same
> datasource, winform databinding will keep the synchronization for these 2
> controls while databinding.
>
> But in your code below:
> this.tbxDesTypeCode.DataBindings.Add ("Text",cbxDesType.SelectedValue,
> null);
> You bind TextBox.Text property to SelectedValue, so the combobox and
> TextBox are bound to 2 different datasouce, and there is no synchronization
> or between these 2 databindings. When we change the selected item in
> combobox, the textbox has nothing knowledge of the change, so its text will
> not change at all.
>
> The correct way to keep the synchronization is set the same
> datasource(nvl.BindableList) for both combobox and textbox, then set
> "Value" as Binding class's third parameter.
>
> I have writen a sample like below:
> public class customized_class
> {
> private int m_intval=0;
> public int intval
> {
> get
> {
> return m_intval;
> }
> set
> {
> m_intval =value;
> }
> }
>
> private string m_strval="aaa";
> public string strval
> {
> get
> {
> return m_strval ;
> }
> set
> {
> m_strval =value;
> }
> }
> }
>
> private customized_class[] arr;
> private void Form1_Load(object sender, System.EventArgs e)
> {
> arr=new customized_class[3];
> for(int i=0;i<3;i++)
> {
> arr[i]=new customized_class();
> arr[i].intval=i;
> arr[i].strval=i.ToString()+"setvalue";
> }
> this.comboBox1.DisplayMember="strval";
> this.comboBox1.ValueMember="intval";
> this.comboBox1.DataSource=arr;
>
> this.textBox1.DataBindings.Add(new Binding("Text", arr, "strval"));
> }
> It works well on my side(with synchronization).
> =====================================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! -
www.microsoft.com/security > This posting is provided "as is" with no warranties and confers no rights.
>