Solved

move to next cell in datagridview

Posted on 2009-07-10
4
1,058 Views
Last Modified: 2012-05-07
Hi all,
I have a datagridview and I've set that the MaxInputLenght of each TextBoxColumn is 2.
Now i want to pass automatically to the next cell when the user enters 2 characters in one cell.
What is the best event handler i can use for this ? And how to determine when there are already 2 characters entered ?

Regards,
Peter
0
Comment
Question by:ippeter
  • 2
4 Comments
 
LVL 1

Expert Comment

by:zoidi
ID: 24821998
Hi,

You could give the event "CellValueChanged" a try to detect if the user inputs some text in the cell. You could simply check if the length of the string inside the cell equals 2 and then jump to the next cell.

Regards,
Zoidi
0
 

Author Comment

by:ippeter
ID: 24822134
Hi,
I've tried it with the event "CellValueChanged", also with "CellBeginEdit" but it doesn't work.
I think i can't check the lenght of the string of the cell because the inputted value is only assigned to the cell when i click to another cell.
I'm not going to use this feature. The user has to push the Tab button to go to the next cell. And that works.
Thanks anyway,
Peter
0
 
LVL 6

Accepted Solution

by:
nandithaa earned 500 total points
ID: 24838430
Try this:

DataGridViewTextBoxEditingControl TextBoxControl;

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            TextBoxControl = e.Control as DataGridViewTextBoxEditingControl;
            if (TextBoxControl != null)
            {
                TextBoxControl.KeyPress += TextBoxCellEditControlKeyPress2;
            }
        }

private void TextBoxCellEditControlKeyPress2(object sender, KeyPressEventArgs e)
        {
            int length = TextBoxControl.Text.Length;
            if (length == 2)
            {
                dataGridView1.CurrentCell = dataGridView1.CurrentRow.Cells[1];
            }
        }
0
 

Author Closing Comment

by:ippeter
ID: 31601996
Hi Nandithaa,
I've tried this and it words perfect.

Regards,
Peter
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question