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

Setting the SelectedItem

1 Answer 108 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 29 Dec 2009, 09:34 PM
Below is my code for populating a Rad Combo box. It works fine (shown as reference to my question).

....
foreach
(CommonClassLibrary.DataObjectReference _control in _list)

  {

Telerik.Windows.Controls.

 

 

RadComboBoxItem _item = new Telerik.Windows.Controls.RadComboBoxItem();

  _item.Content = (

string)_control.ObjectName;

 

 

  _item.Tag = (

int)_control.ObjectID;

 

 

  cboLocationStatus.Items.Add(_item);

}

....

Here's the problem. Later, after selecting a transaction record, I want to set the Selected Item.
...

txtLocationDescription.Text = _addressClass.LocationAddressList[0].ThingName;(this works perfectly)

cboLocationStatus.SelectedItem = _addressClass.LocationAddressList[0].ThingStatusID; (this doesn't work)
...

cboLocationStatus.SelectedItem returns null
1 How do I set the SelectedItem (or SelectedValue) please?
2 Please could you also point me to the documentation on this as I feel like I am asking a pretty simple question and should be able to resolve this myself, but the only docs I can find use SelectedIndex=0, which in 20 years I have never had to use.

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 1
answered on 29 Dec 2009, 11:33 PM
I've worked it out thanks, and here it is for anyone else who gets stuck.

Telerik.Windows.Controls.

RadComboBoxItem _selectedItem = null;

 

 

foreach (Telerik.Windows.Controls.RadComboBoxItem _item in cboLocationStatus.Items)

 

{

 

if ((int)_item.Tag == _addressClass.LocationAddressList[0].StatusID)

 

_selectedItem = _item;

}

 

if (_selectedItem != null) cboLocationStatus.SelectedItem = _selectedItem;

If there is a better way, please let me know

 

Tags
ComboBox
Asked by
Steven
Top achievements
Rank 1
Answers by
Steven
Top achievements
Rank 1
Share this question
or