Radlistbox items won't unselect

Thread is closed for posting
2 posts, 0 answers
  1. Bexm
    Bexm avatar
    67 posts
    Member since:
    May 2007

    Posted 08 Oct 2008 Link to this post


    I have a rad listbox which when someone clicks on an item if its already selected I need it to unselect. Also When a particular button is clicked I need everything to be unselected, but its not working! It leaves a black outline round the item and when I call the selected items in code its still selected!

    I have taken my listbox and put it on a simple test form and it still does it!

    Here is my code:

    1  private int selectedIndex;  
    2         public TEST()  
    3         {  
    4             InitializeComponent();  
    5         }  
    7         private void radListBox1_SelectedIndexChanged(object sender, EventArgs e)  
    8         {  
    9             int newIndex = radListBox1.SelectedIndex;  
    10             if (newIndex == selectedIndex)  
    11             {  
    12                 DeselectAllElements();  
    13             }  
    14             else 
    15             {  
    16                 selectedIndex = newIndex;  
    17             }     
    18         }  
    19         public void DeselectAllElements()  
    20         {  
    21             radListBox1.ClearSelected();  
    22             radListBox1.SelectedIndex = -1;  
    23             selectedIndex = -1;  
    24         }  
    25         private void TEST_Load(object sender, EventArgs e)  
    26         {  
    27             string[] list = "blah1,blah2,blah4,blah5,blah6".Split(',');  
    28             radListBox1.DataSource = list;  
    29         } 

    Please help!

    What am I doing wrong!

  2. Nick
    Nick avatar
    767 posts

    Posted 09 Oct 2008 Link to this post

    Hello Bexm,

    Thank you for your question.

    ListBox controls in general support selected items (yellow background), and an active item (border). When the ListBox gets focus, the active item is shown so that keyboard users can know where they are when navigating with up/down.

    I checked the retrieval of the selected item after the ClearSelected() function was called and it was null, so I think that it works correctly. If I am wrong, please open a Bug Report and attach a sample application demonstrating the issue. 

    About the active item (border) - you can remove it visually by applying a theme that does not draw a border (please see the attached archive) or you can remove it entirely by using the following code whenever needed:  

    this.radListBox1.Items[0].SetValue(RadListBoxItem.ActiveProperty, false); 

    Don't hesitate to contact me if you have further questions.

    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top