tags:

views:

19

answers:

1

I have a datagridview on a form, and I want a specific cell in the first row to be in edit mode when the form opens and when the selection changes. The DataGridView selectmode is set to "FullRowSelect" and in the selection change event I have the following code:

if (dgvReconList.SelectedRows.Count == 1)
{
    dgvReconList.CurrentCell = dgvReconList.SelectedRows[0].Cells["colReferralDate"];
    dgvReconList.BeginEdit(true);
}

That code works like a charm when I change the selection. The problem is that when I try to set the desired cell in the first row to edit mode (using above code) when the form opens. The first row is selected, and the desired cell is the "current" cell, but it is not in edit mode. I have tried using the above code in the forms activate event, the load event, and several others with no luck.

How can I get the cell to be in edit mode as soon as the form opens?

A: 

Do simple three steps.

In the form load event -> After loading the data into the DGV

  1. Set the DGV property EditMode to EditOnEnter.
  2. dgvReconList.CurrentCell = dgvReconList[desiredColumnIndex, 0];
  3. dgvReconList.CurrentCell.Selected = true;

This will directly set the current sell in edit mode.

JPReddy
Brilliant! So simple. Thanks for the help!
Jesse