Share via

Editable datagridview

ankit goel 766 Reputation points
2023-10-23T15:56:02.0266667+00:00

i have a textbox and a datagridview . and the following code on the textbox keydown event

               case Keys.Enter:
                        {                           

                                datagridview1.Focus();
                                datagridview1.CurrentCell = datagridview1.Rows[0].Cells[0]; //                          
                              

                            }

                            e.Handled = e.SuppressKeyPress = true;
                            break;
                        }
                }
            }
        }


i have 2 problems here

  1. regarding BeginEdit(true) : what is the ideal method for beginEdit(true) as my purpose is as soon as the datagridview gets in focus by any control on the form , it should be edit mode straight away . so what method should i choose
    Onenter method or OnCellEnter
  2. i want that the datagridview's first cell of first column and first row should be the first cell by which the datagridview gets in editing mode . what should be better choice
dataGridView1.Rows[rowindex].Cells[columnindex].Selected = true;

or

datagridview1.CurrentCell = datagridview1.Rows[0].Cells[0];
Developer technologies | Windows Forms
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

KOZ6.0 6,810 Reputation points
2023-10-23T16:16:44.5133333+00:00

Here is a sample I wrote. Please modify it to suit your requirements.

https://learn.microsoft.com/en-us/answers/questions/1391288/previous-row-value-copies-in-current-value

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.