Hi,
Inthat scenario, when I try to edit the selected item, you'll see thelist.Selected Value is not changed.
But if you press button to get the Selected Value, you'll it's already = null.
It should keep the selected value, because it's needed to update data (text), using the id as value in a DB table..
public partial class RadForm2 : Telerik.WinControls.UI.RadForm
{
RadDropDownList list = new RadDropDownList();
TextBox tb = new TextBox();
Button b = new Button();
public RadForm2()
{
InitializeComponent();
this.Controls.AddRange(new Control[] { list, tb, b });
list.DropDownStyle = RadDropDownStyle.DropDown;
list.Location = new Point(30, 30);
list.Width = 100;
list.Height = 25;
list.DisplayMember = "name";
list.ValueMember = "id";
list.NullText = "not selected";
list.SelectedValueChanged += list_SelectedValueChanged;
tb.Location = new Point(30, 70);
tb.Width = 100;
tb.Height = 25;
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
dt.Rows.Add(1, "one");
dt.Rows.Add(2, "two");
dt.Rows.Add(3, "three");
dt.Rows.Add(4, "four");
dt.Rows.Add(5, "five");
list.DataSource = dt;
b.Location = new Point(30, 110);
b.Width = 100;
b.Height = 25;
b.Text = "Get Selected Value";
b.Click += b_Click;
}
void b_Click(object sender, EventArgs e)
{
tb.Text = list.SelectedValue + " <----> " + list.SelectedText;
}
void list_SelectedValueChanged(object sender, EventArgs e)
{
tb.Text = list.SelectedValue + " <----> " + list.SelectedText;
}
}
9 Answers, 1 is accepted
Thank you for writing.
I have tested this with the latest version and the behavior is correct on my side. With which version are you testing this? I have attached a small video as well.
I am looking forward to your reply.
Dimitar
Telerik by Progress

Ok, what if I want to Update the Name of the Selected ID in a Database?
----> create table aTable (ID int, NAME varchar )
DataTable dt = .. select * from aTable
RDlist.DataSource = dt;
RDlist.ValueMember = name
RDlist.DisplayMember = name
If I need to update the name with UPDATE button, then I select the item and update its name.
Then I expect the SelectedValue is still the ID of the item.
And I just use update aTable set name=list.Text where id=SelectedValue
I have been doing that way for ages :)
In that scenario that you have, I must each time keep the previously selected value and use it when need to update.


sorry in previous RDlist.ValueMember = id
good if EDIT would be added to post div
I still don't understand which is the exact behavior that you want to avoid. Could you please send me the code that you are using for the update and specify the exact moment where the index is not valid?
Thank you in advance for your patience and cooperation.
Regards,
Dimitar
Telerik by Progress

In case of when DataSource is a table lime I said with id&value you would consider the scenario when it used to update the data in table/
Let's say we have a simple table:
DIC_COMPANY
ID | NAME
=====================
11 Telerik Co.
12 Microsoft Inc.
13 ITBRIGADA Inc.
When such table is loaded, then the value is ID and the dataText - NAME
When a user selects one of the items, it supposed that the ID value in SelectedValue
Then user would like to rename the company name fromTelerik Co. to Telerik Corp.
If the SelectedValue contains its ID then it's easy to get all data to do the update DML command.
ID is in SelectedValue and the new name in Text..
Got My idea?
In 2012 it was like that, and it was perfect.
I understand your scenario now. You can just set the SyncSelectionWithText property and then you will get the correct index:
list.DropDownListElement.SyncSelectionWithText =
false
;
I hope this will be useful.
Regards,
Dimitar
Telerik by Progress

Wow!!! Cool :)
Lot of respect!!