c# SelectNextControl and error

I am trying to speed up some data entry on a form so if a user enter 3 characters it would tab to the next control.   On another windows form using just standard text boxes not toolstrip text box this code works...but using the tool strip text box I get the following error.  See code below and thanks in advance

Error      1      The best overloaded method match for 'System.Windows.Forms.Control.SelectNextControl(System.Windows.Forms.Control, bool, bool, bool, bool)' has some invalid arguments
private void WidthChanged(object sender, EventArgs e)
        {
            if (twidthToolStripTextBox.TextLength == 3)
            {
                this.SelectNextControl(this.twidthToolStripTextBox,true,true,false,false);
            }
        }

Open in new window

BBQMemphisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
ToolStripTextBox inherits from Component, not Control. Can you not just manually set the focus to the ToolStripTextBox? Modify your code like this:
private void WidthChanged(object sender, EventArgs e)
        {
            if (twidthToolStripTextBox.TextLength == 3)
            {
                this.SelectNextControl(this.twidthToolStripTextBox.Control,true,true,false,false);
            }
        }

Open in new window

0
käµfm³d 👽Commented:
Disregard the line

    Can you not just manually set the focus to the ToolStripTextBox?

I forgot to erase it  :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BBQMemphisAuthor Commented:
thanks kaufmed that got rid of the error but did not move the focus (or tab to my next textbox)
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Mike TomlinsonMiddle School Assistant TeacherCommented:
If you need it generic (so you can use it for multiple controls then just send Tab:

    SendKeys.Send("{TAB}");
0
lazyberezovskyCommented:
I know that solution already accepted, but anyway :)
Set toolStripTextBox_KeyUp as KeyUp event handler of ToolStripTextBoxes. Mind, that I suggested to use Tag property of ToolStripTextBox as value of characters could be entered before navigation to next control.
GL :)
// Precondition: set ToolStripTextBox.Tag property to expected text length.
private void toolStripTextBox_KeyUp(object sender, KeyEventArgs e)
{
    ToolStripTextBox textBox = sender as ToolStripTextBox;
    int expectedTextLength = Int32.Parse((string)textBox.Tag); // E.g. 3

    if (textBox.Text.Length == expectedTextLength)            
        SelectNextControl(sender as ToolStripItem);
}

private void SelectNextControl(ToolStripItem currentItem)
{
    ToolStrip toolStrip = currentItem.Owner;
    ToolStripItem item = toolStrip.GetNextItem(currentItem, ArrowDirection.Right);
    bool isLastItem = (toolStrip.Items.IndexOf(currentItem) == toolStrip.Items.Count - 1);

    if (isLastItem)
    {                
        SelectNextControl(toolStrip, true, true, false, false); // Jump from ToolStrip to next control.
        return;
    }
    
    if (item is ToolStripTextBox)
    {
        ((ToolStripTextBox)item).Focus(); // Set focus to next ToolStripTextBox.
        return;
    }

    // Current ToolStripItem is not ToolStripTextBox.
    SelectNextControl(item);
}

Open in new window

0
lazyberezovskyCommented:
Ah, one moment more: it's better to use KeyPress event.
0
lazyberezovskyCommented:
Me again :)
Forgot that items are ToolStripTextBox-s. So, TextChanged event will be the best solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.