Setting the SelectedItem

2 posts, 0 answers
  1. Steven
    Steven avatar
    26 posts
    Member since:
    Jan 2008

    Posted 29 Dec 2009 Link to this post

    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.

     

     

     

     

     

     

     

  2. Steven
    Steven avatar
    26 posts
    Member since:
    Jan 2008

    Posted 29 Dec 2009 Link to this post

    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

     

Back to Top