last day (14 days later) » 

3:21 PM
0
Q: why ProcessCmdKey() does not handle focus of controls?

Phill GregganIn my application shown on this youtube video has a numericupdown control numericupdown3 in a groupbox and outside of the group box has some other textboxes. when the cursor is in numericupdown control and when i hit tab it should move the cursor to textbox3 i.e. the first textbox under the group...

 
Have you had a look at the tab order of your controls?
 
@SteveMitcham i have updated the post with some code
@BerndLinde yes numericupdown3 is 1, textbox3 is 2 and tbx3 is 3
 
Are the controls in different panels/groupboxes?
 
@BerndLinde the numericupddown is in a groupbox but all others are outside of group box and they are just on the form
 
Might it be possible to convert the video into a gif? I am intrigued and would like to help, but feel that without seeing the video I am missing something (youtube blocked at the office)
 
3:21 PM
@BerndLinde atm im converting the youtube to gif i will update the post with gif asap : )
@BerndLinde i have updated the post with the animated gif : )
 
In the gif the TabIndex of textbox3 is 2. But since it is in a second group/panel, it should have a TabIndex of 0, tbx3 a TabIndex of 1. The TabIndex resets to 0 for each new group of controls
Additionally, your Console.WriteLine will output the seemingly correct ActiveControl inside the event, but since you call return base.ProcessCmdKey(ref msg, keyData); after setting the ActiveControl, it will revert back to it's original order and not heed your changes
 
3:38 PM
sorry about the delay
 
No problem :)
 
@BerndLinde still there is a problem i have reset the tab as u said but still same error
@BerndLinde i did not get what you were on about ProcessCmdKey() that it rolls back to the original order
 
Since you are calling the base.ProcessCmdkey after setting your changes, it will handle the rest of the tabbing out as normal
Instead of your current code, add a return true; after your Console.WriteLine line of code
 
Previously i did that before resetting the tabs but let me try this time?
@BerndLinde when i set this to true, if there are event handlers for the following control it will not execute those event hanlders. But for this matter it solved the tab problem. But there will be another errror that because it returns true, it will stop the execution of all event handlers afterwards, right?
 
Yupe, that is correct
The Leave events of the controls will not fire
So that is the dirty fix, now to try and get the right fix
Is it possible to upload the form? (If it doesn't contain sensitive information)
 
4:00 PM
@BerndLinde i cannot post the whole form, is it possible for you to point where this problem might be causing becuase atm return true from processCmdKey() works but it kills all the other events that follows it... the enter event of textbox3 moves the text on to to the left side (alignment) this will not work
 
The various methods that I would try and locate the problem is by firstly checking all the tab orders (which you already did), then handling the Enter, Leave, Activated and Deactivated events and log the messages to see the flow of what it takes after you leave that control
Also, you could try and handle the KeyPressed event of the numericUpDown control and set the focus to the textbox3 control, instead of handling the ProcessCmdKey, not entirely sure if that would work
You are not able to recreate this issue in an MCVE?
 
@BerndLinde okay thats very informative, TX, please post as answer on my post to get points! : )
@BerndLinde MCVE?
 
and which part should be in the answer? :)
and I would rather post an answer when the clean fix is established instead of the dirty on, since the dirty fix brings along additional potental bugs
 
@BerndLinde well return of true solves but it actually partially solves becuase i do i have written other events to follow it
 
aye, which is why the desire to resolve it cleanly is big, instead of the dirty way :)
 
4:06 PM
@BerndLinde this might take some time as this is a first time i have encoutered this problem with the tab, when i figured i will post a comment ;)
 
ok :) happy hunting and hope that you can figure it out cleanly. I personally love these kind of weird issues
 
sometimes weird problems are good problems, TX
 
Hang on, did you have this problem before you implemented the ProcessCmdKey event handler?
 
4:36 PM
@BerndLinde Yes but guess what, i had a hidden NumericUpDown under the groupbox, which i have added couple of days ago and forgotten to document about it. So basically ProcessCmdKey or KeyPress(Keypress does not work for other than number in NumericUpdown) is a waste of time. The only think i had to use to get it right was to set the TabIndex to zero once comes out of the groupbox
@BerndLinde so i would give point to TabIndex reset to 0. please post as answer : )
 
Ok, will update my answer :) Always the small details :D
 
@BerndLinde could you also mention about the resetting the tab solves it without any processCmdKey use at all
 
Done editing the answer with all the information in it (Both the clean and dirty method)
 

last day (14 days later) »