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

Custom listbox with checkboxes

3 Answers 88 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Konrad Sikorski
Top achievements
Rank 1
Konrad Sikorski asked on 02 Sep 2013, 08:35 AM
Hi,
I would like to create control that will show simple text items with checkboxes. User should be able to navigate through items by arrows (up/down) (nice to have navigation by typing searched item). RadListbox has all this functionality. But I don't want to automatically select item when user click on it by mouse or when he navigate using arrow. I also don't want to highlight selected item, but only that which is focused and when control lost focus the highlight should also gone.

Is it possible to achieve this functionality using RadListBox?

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 04 Sep 2013, 12:09 PM
Hello,

Unfortunately it is not possible to achieve the exact scenario with the current version of RadListBox. Removing the selection by the mouse is currently not possible as it is one of the main features of the control and is handled in the code of the control.

You can find attached to my response a possible approach in achieving ListBox with CheckBoxes in its items, hope this is helpful.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Konrad Sikorski
Top achievements
Rank 1
answered on 09 Sep 2013, 01:57 PM
Thx Vladi,

More less I have my list working. I have last issue related to TAB navigation. When you using tab to naviage into your list control than nothing is selected on start, the seccond tab will focus first item and user can navigate to next items by arrows. Next TABs will focus next controls.

What I want to achieve:
1. your focus is one control before your list control
2. press tab your list focus should got focus
3. use arrows up/down to navigate to item
4. press spacebar to select items
5. press tab to go to next control

I have already disabled tab navigation inside list, and i am able to go into/out control using single tab.
myRadListBox.KeyDown += (sender, e) =>
{
if (e.Key == Key.Tab)
            {
                e.Handled = true;
 
                var parent = this.Parent as Panel;
 
                if (parent != null)
                {
                    var controls = parent.Children
                        .OfType<Control>()
                        // for some controls tabs Index is set correctly but isTabStop is still false
                        //.Where(c => c.IsTabStop)
                        .Where(c => c.TabIndex != Int32.MaxValue)
                        .OrderBy(c => c.TabIndex);
 
                    var nextControl = (!Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
                        ? controls.FirstOrDefault(c => c.TabIndex > this.TabIndex)
                        : controls.LastOrDefault(c => c.TabIndex < this.TabIndex);
 
                    if (nextControl != null) nextControl.Focus();
                }
            }
}

I couldn't find how to focus first item when control got focus.
I have something like this:
myRadListBox.GotFocus += (sender, args) =>
                {
                    var items = this.ChildrenOfType<RadListBoxItem>().ToList();
 
                    if (!items.Any(i => i.IsFocused)) items[0].Focus();
                };

The problem is that RadListItem doeant has IsFOcused property. Any sugestion? :)
0
Vladi
Telerik team
answered on 12 Sep 2013, 08:31 AM
Hello,

We tried to reproduce the issue but o no avail.

With the first Tab keyboard key press the focus correctly goes to the control and navigation and selection with the keyboard is available. When the focus is inside the RadListBox control in order for the first Tab press to move the focus out of the control you will need to make sure that all of the controls inside the custom ItemTemplate have their IsTabStop property set to False. This would cause the focus to not be passed to them when you press the Tab keyboard key.

I created and attached a sample project for you that shows the described behavior.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ListBox
Asked by
Konrad Sikorski
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Konrad Sikorski
Top achievements
Rank 1
Share this question
or