Click here to Skip to main content
15,559,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to stop enter key to go the next row rather I want it to go to next cell in a datagridview in C#.NET(3.5)

How I stop cursor to do that?
Here is the code:
C#
private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
{
    try
    {
        dataGridView1.Refresh();
        int Secondrowindex = Convert.ToInt32(dataGridView1.CurrentRow.Index);
        int rowcounter = dataGridView1.Rows.Count;
        int asd = Convert.ToInt32(dataGridView1.CurrentCell.ColumnIndex);
        if (asd <= 5 && Secondrowindex == rowcounter - 1)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (asd == 5)
                {
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex - 4, dataGridView1.CurrentRow.Index];
                }
                else if (asd == null)
                {
                }
                else
                {
                    string asew= dataGridView1.EditMode.ToString();
                    Console.WriteLine(dataGridView1.CurrentCell.EditedFormattedValue);
                    dataGridView1.CurrentCell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex + 1, dataGridView1.CurrentRow.Index];
                }
            }
        }
        else if (asd == 5 && rowcounter == Secondrowindex + 1)
        {
            if (e.KeyCode == Keys.Enter)
            {
                dataGridView1.CurrentCell = dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1];
            }
        }
        else
        {
        }
    }
    catch (Exception gf)
    {
        Console.WriteLine(gf.StackTrace);
    }
}
Posted
Updated 14-Mar-10 4:48am
v2

1 solution

See the article in this page, this is for VB.Net, but you will be able to port it across to C#

http://arsalantamiz.blogspot.com/2008/07/making-enter-key-move-to-next.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900