Quantcast
Viewing all articles
Browse latest Browse all 18858

WPF select ListViewItem using enter key

Hi,

I have ListView like below. I want to navigate ListViewItem using keyboard up and down key. I implemented that functionality and working fine using this code:

private void SelectItemKeyDown(object param)  --- similar code for UP Key
        {
            if (((ListView)param).Items.Count > 0)
            {
                if ((((ListView)param).SelectedIndex + 1) < ((ListView)param).Items.Count)
                {               
                    var item = ((ListView)param).ItemContainerGenerator.ContainerFromIndex(((ListView)param).SelectedIndex + 1) as ListBoxItem;
                    if (item != null)
                    {
                        Keyboard.Focus(item);
                    }
                }
            }
        }

Image may be NSFW.
Clik here to view.

But My question is: when I do this : Keyboard.Focus(item), it is basically selecting that item. I don't want to select item when I press up and down key, it just need to highlight next or previous item. I want to select Item only when I press enter key.

Right now it is selecting printer when press up and down arrow.

How would i do that?

Thanks

Dee



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>