datagridview - set focus

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];
}
 
B

Beth

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
 
B

Berryl Hesh

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];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top