Click here to Skip to main content
Sign Up to vote bad
good
See more: WPF
I've got a WPF ListView with ComboBoxes in the headers (meant for filtering in the list, see sample below). Keyboard navigation is awkward and I cannot get it right:
 
If the user presses cursor(arrow)-up when the first item in the list is selected, focus moves to the ComboBox in the header of the first column.
And then it's trapped there, pressing down walks the elements in the ComboBox; it does not moves focus back to the list.
Pressing TAB moves focus to the next control in the window. There doesn't seem to be a way to get focus to the list elements anymore by keyboard.
I guess what I want is that a) pressing 'arrow up' on the first element of the list does not transfer focus to the header, and b) that the list and header part can be separately reached by tabbing into them. I cannot seem to get this right.
 
Can this be done?
 
Sample code:
<ListView>
    <ListView.View>
        <GridView>
            <GridViewColumn>
                <GridViewColumn.Header>
                    <ComboBox Width="150">
                        <ComboBoxItem Content="Filter Item 1" />
                        <ComboBoxItem Content="Filter Item 2" />
                    </ComboBox>
                </GridViewColumn.Header>
            </GridViewColumn>
 
            <GridViewColumn>
                <GridViewColumn.Header>
                    <ComboBox Width="150">
                        <ComboBoxItem Content="Filter Item 1" />
                        <ComboBoxItem Content="Filter Item 2" />
                    </ComboBox>
                </GridViewColumn.Header>
            </GridViewColumn>
        </GridView>
    </ListView.View>
    <ListViewItem Content="Item 1" />
    <ListViewItem Content="Item 2" />
    <ListViewItem Content="Item 3" />
    <ListViewItem Content="Item 4" />
</ListView>
 
<TextBox or other control />
 
Thanks!
Posted 20 Aug '12 - 23:30
Edited 21 Aug '12 - 4:14


2 solutions

Tried a few hours, never got it quite right. Closest I've got is:
private void testListView_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (testListView.SelectedIndex == 0)
    {
        if (e.Key == Key.Up)
        {
            e.Handled = true; // Don't move focus to the header/filter row on arrow-up.
            return;
        }
    }
}
This fixes the main part of the problem (focus is moved to the filter on up arrow).
 
Couldn't get elegantly tab behavior from another control into the filter comboboxes part, then the list part, then to the next control however. No combination of KeyboardNavigation.TabNavigation, ControlTabNavigation and DirectionalNavigation got the desired behavior.
  Permalink  
Yes, it can be done!
 
You need to work with some events.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 253
1 Rohan Leuva 220
2 Sergey Alexandrovich Kryukov 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 6,799
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid