Solved

move to next cell in datagridview

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

20 Experts available now in Live!

Get 1:1 Help Now