Solved

move to next cell in datagridview

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

856 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