Home > other >  Setting datagridview in editing mode
Setting datagridview in editing mode

Time:10-22

I am working on a c# datagridview project where my requirement is that as soon as the datagridview gets focus it's first cell of first row and first column should get focus and that cell should come into edit mode . I mean that i can straightforward type into that cell . Any suggestions for that . Which event and code i have to use .

CodePudding user response:

You need to use the Enter event of the DataGridView.

I added a simple DataGridView to my form and added its Enter event. Here's my testing code:

public Form1()
{
    InitializeComponent();

    // empty row and column so you have something to edit
    dataGridView1.Columns.Add("col1", "Column 1");
    dataGridView1.Rows.Add();
}

private void dataGridView1_Enter(object sender, EventArgs e)
{
    dataGridView1.Rows[0].Cells[0].Selected = true;
    dataGridView1.BeginEdit(false);
}

If your DataGridView already has a data source, you need to be careful about the data type of the first column and the data that will be typed.

  • Related