datagridview select next column on enter key
  • if i click the enter button the data grid view focus the next cell(next column)
    if the cell is end of the grid view cell and click the enter button means  the next row should be iterate 
  • 5 Comments sorted by
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    hi @Akwin_Lopez you are lucky because i already tired it in my code and below i am pasting simplest code who is end of my research on this topic kindly apply below code ..

    you have to use KeyDown and CellEndEdit Event of datagridview.

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    e.SuppressKeyPress = true;
                    int iColumn = dataGridView1.CurrentCell.ColumnIndex;
                    int iRow = dataGridView1.CurrentCell.RowIndex;
                    if (iColumn == dataGridView1.Columns.Count - 1)
                    {
                        if (dataGridView1.CurrentRow.Index + 1 != dataGridView1.RowCount)
                        {
                            dataGridView1.CurrentCell = dataGridView1[0, iRow + 1];
                        }
                    }
                    else
                        dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow];

                }
            }
            private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                SendKeys.Send("{up}");
                SendKeys.Send("{right}");
            }

  • but i have to write the same code for 11 grids ow can i write public
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    make function and call it on all grids.
  • thank u its working well waqas
  • this code is very helpful to me thank you dear 

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative