?
Solved

move to next cell in datagridview

Posted on 2009-07-10
4
Medium Priority
?
1,064 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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