This is a migrated thread and some comments may be shown as answers.

DataBinding issue with ComboBox

4 Answers 150 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stargazer
Top achievements
Rank 2
Stargazer asked on 12 May 2010, 07:29 PM
And probably with RadListBox also.

The problem is as follows: I have a RadComboBox, with DataSource, DisplayMember and ValueMember defined. It get's populated just fine:
cmbNewTipoUtente.ValueMember = "ID_TipoUtente";  
cmbNewTipoUtente.DisplayMember = "Designacao";  
cmbNewTipoUtente.DataSource = dt; //<- DataTable 

The same RadComboBox has a DataBinding on SelectedValue to a property on a POCO object. Something like this:
cmbNewTipoUtente.DataBindings.Add("SelectedValue", mNewTipoUtente, "ID_TipoUtente"true, DataSourceUpdateMode.OnPropertyChanged, null); 

Also have the SelectedIndexChanged event subscribed where I check for some conditions. In the event, I'm checking the value on the ID_TipoUtente property so I can pass it to a method on my business layer. This is where the problem lays (and I think it is a bug), whenever I selecte an item on the RadComboBox, the value of my property do not get updated.

I tryed to open a Bug Report, but it seems there's also a bug on My Account section of the site, since there is only one product available to me, where should be almost all of them. lol

This is a big issue since many of my features are broken because of this and can cause me some pain with my clients.

4 Answers, 1 is accepted

Sort by
0
Stargazer
Top achievements
Rank 2
answered on 13 May 2010, 05:08 PM
Hello, I managed to get my account to work again and managed to open a ticket. Meanwhile me and a colleague, were able to come up with a workaround for this issue, which I'll put here for those of you experiencing same issues.

We created a new class, inheriting from RadComboBox, and override OnSelectedIndexChanged. In there, basically we access the binding object and force the change to it. So, as an image is better than a thousand words, here we have:

protected override void OnSelectedIndexChanged(EventArgs e) 
    //Pesquisa e verifica se a propriedade SelectedValue está bound,  
    //caso esteja actualiza o valor do objecto 
    if (base.DataBindings != null && base.DataBindings.Count > 0) 
    { 
        foreach (Binding binding in base.DataBindings) 
        { 
            if (binding.PropertyName.Equals("SelectedValue")) 
            { 
                object objBound = binding.DataSource; 
                string nomePropriedade = binding.BindingMemberInfo.BindingField; 
 
                PropertyInfo propriedade = objBound.GetType().GetProperty(nomePropriedade); 
 
                if (propriedade.GetValue(objBound, null) != this.SelectedValue) 
                { 
                    binding.WriteValue(); 
                } 
            } 
        } 
    }             
 
    //Chama o método base 
    base.OnSelectedIndexChanged(e); 

Same results are achieved if one adopts the same approach to RadListBox. Hope it helps!
0
Victor
Telerik team
answered on 18 May 2010, 09:38 AM
Hi Stargazer,

Thank you for sharing this information. We will look into the issue and will address it if it is on our side.

Sincerely yours,
Victor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Peter
Top achievements
Rank 1
answered on 07 Aug 2016, 12:16 PM

Hi Victor,

I was trying to databind the RadTextBox so that when user choose one item in the RadListView,the related data can be shown in the textbox. But  I found that there was no DataSource property for RadTextBox and I searched on the Internet,someone suggested RadComboBox(hide the dropdown arrow).The problem is I could not find the RadComboBox in the toolbox,could you give me some guide?

Thanks,

Peter

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Aug 2016, 10:28 AM
Hello Peter,

Thank you for writing. 

Since Q2 2010 RadDropDownList was introduced which replaced the RadComboBox. That is why you couldn't find it in the toolbox. Additional information is available here: http://docs.telerik.com/devtools/winforms/dropdown-listcontrol-and-checkeddropdownlist/upgrading-to-dropdownlist-and-listcontrol

However, you can use simple data binding with RadTextBox. Here is demonstrated a sample code snippet which result is illustrated in the attached gif file. 
private void Form1_Load(object sender, EventArgs e)
{
    this.customersTableAdapter.Fill(this.nwindDataSet.Customers);
 
    this.radListView1.DataSource = this.customersBindingSource;
    this.radListView1.DisplayMember = "ContactName";
    this.radListView1.ValueMember = "CustomerID";
 
    this.radTextBox1.DataBindings.Add("Text", this.customersBindingSource,
        "ContactName", true, DataSourceUpdateMode.OnPropertyChanged);
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Stargazer
Top achievements
Rank 2
Answers by
Stargazer
Top achievements
Rank 2
Victor
Telerik team
Peter
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or