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

Radlistbox items won't unselect

1 Answer 110 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.
Bexm
Top achievements
Rank 1
Bexm asked on 08 Oct 2008, 02:14 PM
Hello

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:

 private int selectedIndex;  
        public TEST()  
        {  
            InitializeComponent();  
        }  
 
        private void radListBox1_SelectedIndexChanged(object sender, EventArgs e)  
        {  
            int newIndex = radListBox1.SelectedIndex;  
            if (newIndex == selectedIndex)  
            {  
                DeselectAllElements();  
            }  
            else 
            {  
                selectedIndex = newIndex;  
            }     
        }  
        public void DeselectAllElements()  
        {  
            radListBox1.ClearSelected();  
            radListBox1.SelectedIndex = -1;  
            selectedIndex = -1;  
        }  
        private void TEST_Load(object sender, EventArgs e)  
        {  
            string[] list = "blah1,blah2,blah4,blah5,blah6".Split(',');  
            radListBox1.DataSource = list;  
        } 


Please help!

What am I doing wrong!

Bex

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 09 Oct 2008, 02:59 PM
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.

Regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Bexm
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or