Click here to Skip to main content
15,914,162 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all,

i've 5 text-boxes in Windows Form and i focused first text box by using code:textbox1.select(); in d page load and its working.But my question is, i want to select 2nd text box,3rd text box and so on by TAB Key,but control is not selecting next one instead selecting 4th one. So please help me out in that.
Posted

There is a propery called "TabIndex" that you should use.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabindex.aspx[^]
You can also change it directly in the forms editor.
You can just set the TabIndex of textBox1 to 1 and so on.
If you want to do it in code then you could use:
C#
textBox1.TabIndex = 1;
textBox2.TabIndex = 2;
textBox3.TabIndex = 3;
...
 
Share this answer
 
v2
Comments
Espen Harlinn 14-Jan-11 5:54am    
5+ The best answers are nice and simple :)
You need to set the tab index sequentially for all the text boxes.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Jan-11 1:17am    
@Amit: that's correct (a vote of 5). Should be added about proper ordering of parent controls, such as Panels containing those text boxes, to the top of parent/children tree.
Wild-Programmer 15-Jan-11 7:03am    
Thank you Sakryukov for giving in the details :) I do miss on minor details most of the time :(

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