• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1317
  • Last Modified:

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.currentcell = datagridview1.Rows(0).Cells(0)

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.
  • 2
1 Solution
Try this:

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

and make sure that the selection mode is cellselect.
EXTRHMANAuthor Commented:
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.
EXTRHMANAuthor Commented:
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.
Closed, 125 points refunded.
Community Support Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now