Solved

move to next cell in datagridview

Posted on 2009-07-10
4
1,057 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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now