Solved

Programmatically setting the focus on a cell in a datagridview

Posted on 2007-03-26
5
1,283 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:EXTRHMAN
  • 2
5 Comments
 
LVL 4

Expert Comment

by:jtaylor8181
Comment Utility
Try this:

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

and make sure that the selection mode is cellselect.
0
 
LVL 1

Author Comment

by:EXTRHMAN
Comment Utility
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.
0
 
LVL 1

Author Comment

by:EXTRHMAN
Comment Utility
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.
0
 
LVL 1

Accepted Solution

by:
Vee_Mod earned 0 total points
Comment Utility
Closed, 125 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 5 109
Vb.Net Menu 1 21
Help with error message for ReportViewer in VS2015 4 23
SQl help with selection 14 44
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now