473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how to control tabindex when pressing enter in a textbox

i have a windows based application which contains textboxes when i press enter in one textbox then focus should go to next textbox i dont want to hard code like ex: textbox3.focus but i want to control it using the tab index (retriving it from present control then using the tab index guiding the focus to the next control ) could u please suggest me a solution preferbly if u give me sample code



with regards and thanks
vijay
May 28 '07 #1
2 2932
mwalts
38
i have a windows based application which contains textboxes when i press enter in one textbox then focus should go to next textbox i dont want to hard code like ex: textbox3.focus but i want to control it using the tab index (retriving it from present control then using the tab index guiding the focus to the next control ) could u please suggest me a solution preferbly if u give me sample code



with regards and thanks
vijay
Well, try something like this in your keyPressed event for all the textboxes (check or the enter key first)
Expand|Select|Wrap|Line Numbers
  1.             TextBox tbCur = (TextBox)sender;
  2.             int curTabIndex = tbCur.TabIndex;
  3.             foreach(Control ctl in this.Controls)
  4.             {
  5.                 if(ctl.GetType() == tbCur.GetType())
  6.                 {
  7.                     if(ctl.TabIndex == curTabIndex+1)
  8.                     {
  9.                         ctl.Focus();
  10.                         break;
  11.                     }
  12.                 }
  13.             }
Have fun,

-mwalts
May 28 '07 #2
dip_developer
648 Expert 512MB
i have a windows based application which contains textboxes when i press enter in one textbox then focus should go to next textbox i dont want to hard code like ex: textbox3.focus but i want to control it using the tab index (retriving it from present control then using the tab index guiding the focus to the next control ) could u please suggest me a solution preferbly if u give me sample code



with regards and thanks
vijay

Hi cvijaykrishna,

If you want,You dont have to write a single line of code for that...
Textbox has a TabIndex property
Suppose you have 4 textboxes..
set TabIndex Property of the textbox from Properties window like....

TextBox1------------->TabIndex=0
TextBox2------------->TabIndex=1
TextBox3------------->TabIndex=2
TextBox4------------->TabIndex=3


if you have many textboxes go to Design mode of your Form...........then go to View---->Tab Order

Set your TabIndex here by just Clicking the Small squares which will appear at the corner of the textboxes in the order you want
May 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Yoshitha | last post by:
Hi, I want help regarding providing information about form and controls which are presented on the form. when ever user presses f1 if the form has focus then it has to provide information about...
2
by: David Kao | last post by:
HI All: I am currently implementing a TextBox to allow user to type the things the user wants to search. The actual search routine is happening on Textbox Validated event. My user wants me trap...
0
by: Yoshitha | last post by:
Hi, I want help regarding providing information about form and controls which are presented on the form. when ever user presses f1 if the form has focus then it has to provide information about...
1
by: =?Utf-8?B?am9uZWZlcg==?= | last post by:
I keep getting the message after I converted a regular aspx page to now be based on a master page: "Only Content controls are allowed directly in a content page that contains Content controls."...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.