简体   繁体   中英

Setting datagridview in editing mode

I am working on ac# 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM