Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form contains a textBox and Listview displaying records from a SQL Table.
Now my listview populating depending on the criteria of my textbox.Everything is perfectly working.

My problem is when I press the down arrow from my textbox it should focus the listview and select the first row of the listview control. I have written a code as
private void textBox1_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyData == Keys.Down)
               listView1.Focus();
       }


this code is focus the listview and when I press down arrow second time it is selecting second row.
My problem is, it is selecting the first row but it is not visible. like it happens when I press up or down arrow for next time after the focus is in the listview.

what i want is when the listview got the focus it should select the first row and that should visible by color changes (like blue background and white foreground)
Posted

1 solution

You could set listView1.Items[0].Selected = true;
 
Share this answer
 
Comments
[no name] 20-Jan-12 13:15pm    
thank you so much,its working perfectly.
can you help me a little bit more.
I want simultaneously writing and selection to the listview.
Tarakeshwar Reddy 20-Jan-12 14:55pm    
I am not sure I understand your question. What do you mean by writing?
[no name] 20-Jan-12 15:55pm    
writing in the text box and selection in the listview, simultaneously.
Tarakeshwar Reddy 20-Jan-12 16:17pm    
Take a look at http://stackoverflow.com/questions/5179664/how-to-change-listview-selected-row-backcolor-even-when-focus-on-another-control, the same question is asked and an answer has been posted for the same.

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