Live Chat Icon For mobile
Live Chat Icon

How do I move the focus to a ListViewItem that could also be out of view?

Platform: WPF| Category: ListView

You can do so as follows:

[C#]
            this.myList.SelectedItem = o;
            // In case the item is out of view. If so, the next line could cause an exception without bringing this item to view.
            myList.ScrollIntoView(this.myList.SelectedItem);
            ListViewItem lvi = (ListViewItem)myList.ItemContainerGenerator.ContainerFromIndex(myList.SelectedIndex);
            lvi.Focus();

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.