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

Databinding SelectedItem/SelectedValue in a DropDownList

8 Answers 496 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Svein Thomas
Top achievements
Rank 1
Svein Thomas asked on 16 Nov 2010, 02:50 PM
Hi guys,

How can i databind the selecteditem/selectedvalue in a Dropdownlist allready bounded to a table.

Table looks like this:
int ID, string Name;

The DropDownlist is binded to a table of values (datasource). The DisplayMember is set to a "Name" and ValueMember is set to "ID".
I want to use the ValueMember in another kind of binding.

So i tried to do like this. radDropDownList1.DataBindings.Add("Value", MyDataObject, "TextID");

But then i found out that the raddropDownList1 do not contain the Property Value, but it have a SelectedValue.

So i tried to do like this. radDropDownList1.DataBindings.Add("SelectedValue", MyDataObject, "TextID");
But this did not work as expected.

So how do i do it?

Regards
Svein Thomas

8 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 03:06 PM
Hello,

I'm not sure if I understand what you want to do here. I understand that you have a RadDropDownList and that it is bound to a datasource containing Name as the Display Member and Id as the Value member.

Are you saying that you would like to pull the Selected Value or Selected Text from a datasource?
Please ellaborate and I'll do my best to help
thanks

Richard
0
Svein Thomas
Top achievements
Rank 1
answered on 16 Nov 2010, 03:08 PM
I have a "table1" that contains this
ID, Name, TextID (foreign key to the table2)
"Table2" like this:
ID,Name.

radDropDownList contains the Table2's data.
When i select from the radDropDownList, i want to set the Table1's foreignkey to the selected value. (the ID of table2)
All this with databinding.
0
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 03:10 PM
Hello again,

re-reading the title of your thread, you can just set the SelectedText or SelectedValue to select the item that you want. Is this what you mean?
Regards,
Richard

EDIT: Apologies - looks like we posted at the same time.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 03:19 PM
Hi,

As far as I'm aware, this cannot be done through databinding the RadDropDownList. You would need to change the values in your Table1 on the SelectionChanged event of the RadDropdownList.

If I can think of another solution, I'll let you know.
regards,
richard
0
Shawn Shaddock
Top achievements
Rank 1
answered on 09 Feb 2012, 04:33 PM
This is unacceptable especially considering SelectedItem is in the (DataBindings) section of the property grid. I'm trying to use MVVM with this control and it's completely unusable. I need to bind the SelectedItem of the DropDownList to the SelectedItem of my ViewModel.
0
Julian Benkov
Telerik team
answered on 14 Feb 2012, 02:53 PM
Hello Shawn,

Thank you for writing.

I performed some tests with RadDropDownList and I can confirm that simple binding does not be work as expected. I logged the issue in our Public Issue Tracking System. I hope that we will be able to provide a solution regarding the simple binding in one of our next releases. Still, because of the nature of the issue, I am not able to provide you with a specific time frame. Here is a link to the item, where you can add your vote for it: http://www.telerik.com/support/pits.aspx#/public/winforms/9738.

Thank you for your time and cooperation. Your Telerik points have been updated.

Regards,
Julian Benkov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Marsh
Top achievements
Rank 1
answered on 15 Mar 2012, 09:52 AM
Julian,

That is not a satisfactory response.. what is the alternative???

I have my object list bind to a Raddropdownlist. I want to set my selected item but its giving syntax error:

 'ContainerManager.Data.Supplier' cannot be converted to 'Telerik.WinControls.UI.RadListDataItem'.
0
Julian Benkov
Telerik team
answered on 19 Mar 2012, 04:42 PM
Hello Marsh,

Please open a support ticket and send us a sample application to investigate this conversion locally. Thsi will allow us to find the best solution for the case.

Thank you for your time and cooperation.

All the best,
Julian Benkov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
DropDownList
Asked by
Svein Thomas
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Svein Thomas
Top achievements
Rank 1
Shawn Shaddock
Top achievements
Rank 1
Julian Benkov
Telerik team
Marsh
Top achievements
Rank 1
Share this question
or