tags:

views:

171

answers:

2

I'm using a listview to implement some autohelp in my application. The user can type into a file, which I use to scroll to the proper place in the listview. However, if the user changes focus to the listview and types things in there, the listview starts its own processing of the user's input. I want to have the listview enabled and focusable (I'm getting key and mouse events from it), but I want to shut off the "I'll find what you type in here" functionality.

Any ideas?

A: 

You could do a OnKeyPress -> clear selection

Not sure if that would be the best way though.

   MyListView.SelectedItems.Clear()
Jon
+2  A: 

Handle the KeyPress event:

private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar >= 'a' && e.KeyChar <= 'z') // replace with desired conditional
    {
     e.Handled = true;
    }
}

If you set the args event Handled property to true, the underlying control will not process the keystroke.

Michael Petrotta
That's the ticket - worked like a charm. Thanks.