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

SelectedValue and SelectedItem

2 Answers 171 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.
Victoria F
Top achievements
Rank 1
Victoria F asked on 03 Feb 2011, 12:43 AM
Hello.

I have a following problem with the combobox:
First I initialize my combobbox:  Value column is a numeric field (Int64) , Display column is a Text field:
ddb_Broker.ValueMember = dtBrokerList.Columns[0].ColumnName;
ddb_Broker.DisplayMember = dtBrokerList.Columns[1].ColumnName;
ddb_Broker.DataSource = dtBrokerList.DefaultView;
ddb_Broker.SelectedItem = null;

When I retrieve data I need to populate the Broker:
ddb_Broker.SelectedValue = Convert.ToInt64(gl_dtProgram.Rows[0]["in_broker"]);
after this line in debugger ddb_Broker.SelectedValue = null ..... ? WHY ?

Please, help me to set this value. The same story happened with other fields ..

Thank you ,
Victoria.

2 Answers, 1 is accepted

Sort by
0
Victoria F
Top achievements
Rank 1
answered on 03 Feb 2011, 05:19 AM
I found the problem. It works , but if you use SelectedValue property to set the combobox you have to be aware that this property is very sensitive.
SelectedValue must be EXACTLY of the same datatype and the same value as values from the ID column.

If your ID column (ValueMember column) initialized as Int32 but you are trying to assign SelectedValue as Int64 it would not work and vise versa.

Problems that you might have if your ID column (ValueMember column) is a string: If your SelectedValue that you are assigning has trailing spaces. You have to make sure that you TrimEnd() the value.
0
Peter
Telerik team
answered on 08 Feb 2011, 12:13 PM
Hi Victoria F,

Thank you sharing this information with us and I am happy to hear that you resolved the issue.
Do not hesitate to contact us if you have other questions.

All the best,
Peter
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Victoria F
Top achievements
Rank 1
Answers by
Victoria F
Top achievements
Rank 1
Peter
Telerik team
Share this question
or