Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there I would like to implement the TAB effect on multiple textboxes
i.e upon entering the value in a textbox and then hitting the enter key the focus should
automatically get onto the next textbox (as good as entering the data and then hitting the
TAB key which I dont want to do)...So please can some one suggest a way for this
currently I am trying to use this piece of code in PreTranslateMessage()..
C#
if ( (pMsg->wParam == VK_RETURN) )
if( m_CeditCtrlLlaLatDegrees.GetFocus() )
{
  keybd_event( VK_TAB,0x09,0,0);
  // keybd_event( VK_TAB,0x09,KEYEVENTF_KEYUP,0);
}

but the above code just pushes the focus onto the textbox following the one i need for.that is
it moves 2 tabs ahead... i have a total of 20 textboxes all taken from CEdit and all
accept only numeric values.
Also I would like to know the way to retrieve the ID for each of these textboxes
I tried assigning Cedit - control variable and accessing the ID for each of the
textbox ..then through a switch-case statement of a simple if-else code i would
then check which textbox is active and then SetFocus() to the next immediate one
--- all of this in PreTranslateMessage();.
But even this wont work ..So please can someone suggest a way to get this thing to work.
Please let me know the flow/code in detail since I am a newbie ..
Thanks for the help in advance.
Posted
Updated 23-Jan-11 18:17pm
v2

First thing, read this[^]. In MFC the CDialog class contains the CDialog::NextDlgCtrl[^] method which might help you. Don't call keybd_event like you're doing, it's horrible.
 
 
Share this answer
 
v2
hello first of all thanks for all the help..the above idea of yours didnt work either..even PostMessage( WM_NEXTDLGCTL ,0,0 ); shifts the focus to the textbox one after the next so this fails too ..though the TAB effect is done but whats worse is the validation for which i have to click on the message box with mouse and not normally the enter key else the message box for validation (like the range 0-53 for latitude )keep popping up since the focus is on the next control again here the next messagebox!!.

Thanks and regards
 
Share this answer
 
v3
Comments
Emilio Garavaglia 24-Jan-11 1:51am    
Removed the "full bold" for readability
Hello there heres the small piece of code which ensures that the tab is set to the very next textbox and this works about in round robin fashion
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_RETURN))
{
pMsg->wParam = VK_TAB;
}


hope this helps to all having similar thought about coding in VC6..thanks to all again
 
Share this answer
 

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