datagridview - set focus

  • Thread starter Thread starter Berryl Hesh
  • Start date Start date
B

Berryl Hesh

When the dgv control is first initialized I want the focust to be in the 3rd
column of the first row with data. Code below caused the program to
terminate.

Thanks for sharing - BH

public void SetFocusToDataEntry() {
_dgv.Focus();
_dgv.CurrentCell = _dgv.Rows[1].Cells[2];
}
 
Hi, Berryl.

Try commenting out your focus call.
My VB code works without it:
dgvReadOnly.CurrentCell = dgvReadOnly(gridColsToHide, row)

otherwise, it could be a syntax thing. Can't help you with the C# syntax,
sorry.

HTH

-Beth
 
Hi Beth

It turns out I was my test case for this hadn't created a handle for the
control (ie, dgv.CreateControl, which a 'real' form does automatically for
you). That fixed this particular problem.

I probably wouldn't be much help with your VB syntax either :-). Thanks for
your reply.

Berryl

Beth said:
Hi, Berryl.

Try commenting out your focus call.
My VB code works without it:
dgvReadOnly.CurrentCell = dgvReadOnly(gridColsToHide, row)

otherwise, it could be a syntax thing. Can't help you with the C# syntax,
sorry.

HTH

-Beth

Berryl Hesh said:
When the dgv control is first initialized I want the focust to be in the
3rd
column of the first row with data. Code below caused the program to
terminate.

Thanks for sharing - BH

public void SetFocusToDataEntry() {
_dgv.Focus();
_dgv.CurrentCell = _dgv.Rows[1].Cells[2];
}
 
Back
Top