Link to home
Start Free TrialLog in
Avatar of EXTRHMAN
EXTRHMAN

asked on

Programmatically setting the focus on a cell in a datagridview

I have a datagridview that users will enterdata into.  When the form loads the first cell in the NEWROW of the datagrid should have focus and be ready for data entry (blinking cursor).  I am using the following code below to do this but it is not working.

datagridview1.focus
datagridview1.currentcell = datagridview1.Rows(0).Cells(0)
datagridview1.beginedit(true)

Using this I don't get a blinking cursor and I can't just start typing.  I have also tried inserting a row with dumby data in the first cell to see if that helps and it does not.  I also tried removing the datagridview1.focus line but that does not help either.
Avatar of jtaylor8181
jtaylor8181

Try this:

datagridview1.currentcell = datagridview1.Item(0, 0)

and make sure that the selection mode is cellselect.
Avatar of EXTRHMAN

ASKER

jtaylor8181 - Thanks for responding

I tried your suggestion and got the same results.  I had not thought of changing the selection method.


If I hit the enter key I can then start typing.  If that helps at all.
I found a solution that works for this project, but would still like to here anyone elses ideas.

I used sendkeys.send(vbcrlf) on the form_load event

I will leave this question open for a bit longer before I ask for a refund of points.  If someone can give me a better solution then I will reward the points to them.
ASKER CERTIFIED SOLUTION
Avatar of Vee_Mod
Vee_Mod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial