How to make selection move to top of the list?

2 posts, 0 answers
  1. Evan Richardson
    Evan Richardson avatar
    1 posts
    Member since:
    Aug 2009

    Posted 31 Aug 2009 Link to this post

    Hey everyone, hope you can help with this request because I don't know how to quite word it correctly, but I'm going to try my best.

    I'm wondering if there is a way to code the combo box so that when a user selectes a value...and the box closes again, If you reopen the box, the selected value is either at the top or bottom of the list?  

    for example lets say your drop down contains the following:

    1
    2
    3 Selected Value
    .
    .
    .
    .
    20

    And then you select 3.   The drop down will close with that value selected, and then if you click to drop down again, your list now looks like this:


    3 Selected Value
    4
    5
    6
    7
    8
    .
    .
    .


    Same in reverse, so like if 6 was selected, then it would look like this:

    1
    2
    3
    4
    5
    6 selected value.


    I hope that kinda makes sense.

    Thanks.
  2. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 01 Sep 2009 Link to this post

    Hi Evan,

    You can try using the following approach:


    private
     void radComboBox1_SelectedIndexChanged(object sender, EventArgs e) 
         RadItem selectedItem = this.radComboBox1.SelectedItem as RadItem; 
     
         if (selectedItem != null
         { 
             this.radComboBox1.Items.Remove(selectedItem); 
             this.radComboBox1.Items.Insert(this.radComboBox1.Items.Count, selectedItem); 
             this.radComboBox1.Text = selectedItem.Text; 
         } 

    In the SelectedIndexChanged event you can easily insert the SelectedItem at the position you would like it to appear. However, you should also set the Text of RadComboBox so that it does not disappear after you first remove the SelectedItem from the collection in order to insert it at another position.

    I hope this helps.

    Greetings,
    Deyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top