Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1094347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:57:38+00:00 2026-05-16T23:57:38+00:00

I have a listview with a dozen of rows binded to xml. I’d like

  • 0

I have a listview with a dozen of rows binded to xml. I’d like to have a possibility to locate and position the cursor to a certain record. For example:
I have a with these ID, Name, Value:

1, Johny, Cash, USA
2, Jean-Michel, Jarre, France
3, Jeanette, , USA

When I would type “Je”, the SelectedRow would be positioned to ID 2. When I would type “Jeane”, the SelectedRow would be positioned to ID 3. Simply I’d like to have a possibility to search and go to the proper record in the listview. I started building the SearchString and at this point I got stuck:

The one and only possibility in WPF is to use the KeyDown event. Unfortunately, this event return a kind of Key, which I was not able to convert to a string. E.g. when I press “A”, SearchString would be “A”. When I continue typing “B”, SearchString would be “AB” etc. When SelectedItem changes, SearchString will be set to String.Empty. No KeyCode or other useful property/method is available.

And here comes the head rubbing. How can I build the SearchString I need?
When I tried e.Key.ToString(), I got really funny strings – e.g. for 0 on Numpad I get a Key “Numpad0”, for “,” I get “OemComma” etc. I was trying also the TryParse method to char, for key “3” I get a value of “#” etc, it only works flawlessly just for letter A through Z, for other keys TryParse returns false.

The one and only way how to solve this is to build a translation table with a very long kind of “case e.Key.ToString() of”:

"A": SearchString = SearchString + "A";
"System", SearchString = SearchString + " ";
"Numpad0", SearchString = SearchString + "0";
"ArrowUp", do nothing 

etc etc etc.

Isn’t there a more clever and simple way to do this?? Or I just don’t see the trees because of the forest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:57:38+00:00Added an answer on May 16, 2026 at 11:57 pm

    Handle PreviewTextInput instead. Reference: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3fcfbe53-2c72-4fec-a997-dc881d1de72a.

    EDIT:

    Note: The ListView (and ListBox also) internally handles the KeyDown event for some keys to perform selection and navigation. Below are the keys that are internally handled by the ListView:

        Key.Space:
        Key.Return:
        Key.Prior:
        Key.Next:
        Key.End:
        Key.Home:
        Key.Left:
        Key.Up:
        Key.Right:
        Key.Down:
    

    Key.Space is of particular interest because when space is pressed on a ListView, the PreviewTextInput event will not get fired. So to complete your solution, you would have to also add a handler for the ListView.PreviewKeyDown event and check if the space key was pressed in order for you to append the correct whitespace text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView inside another ListView, and I'd like to hide a table
I have a listview that is binded to a ThreadSafeObservableCollection. The background of each
I have a listview which I would like to fill with self created user
I have a ListView that contains a large collection of rows with textboxes that
I have some EditViews in the rows of a ListView. This works just fine
I have a ListView which is populated using a CursorAdapter. I'd also like to
I have listview with some listadapter after click on item from list I'd like
I have a listview that is setup like so: <asp:ListView ID=lv_First runat=server> <LayoutTemplate> <div
I have a ListView that looks like this: Notice how the TextView is getting
I have a ListView control, and I'm trying to figure out the easiest/best way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.