Click here to Skip to main content
15,921,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am developing a window application in C#. I have a listbox filled with country names.
When that form is opened and a key is pressed say G, the country Germany shows at the bottom of the display area. But i want it to display at the top of the display area( listbox).

Thanks,
Posted

1 solution

In the listbox keypress;

C#
private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    //Find the first item that starts with the keypressed, and set it to the top of the list
        listBox1.TopIndex =listBox1.FindString(e.KeyChar.ToString(), 0);
}
 
Share this answer
 
Comments
samip shrestha 1-Sep-11 2:03am    
Thank you Dave Auld.
that was what i needed.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900