How to display the cursor in a datagridview

Posted on 2011-02-24
Last Modified: 2012-06-27
How do i display the cursor in a datagridview when initialy load a form.  I have set the cursor to a selected cell has follows,
However, the cursor does not display until I click on the datagridview.  I have also set the row as selected with the following,
DataGridView1.Rows(0).Selected = True
This also does not display the cursor.
Any thoughts?
Question by:StoneCutter3
LVL 17

Expert Comment

ID: 34970103
use sendkeys to send F2 or call beginedit()

Author Comment

ID: 34970273

I tried with no luck.

DataGridView1.CurrentCell = DataGridView1.Item(2, 0)

Do you have an example?
LVL 17

Expert Comment

ID: 34970463
try setting the edit mode before begining edit, eg

DataGridView1.CurrentCell = DataGridView1.Item(2, 0)
Me.DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically

Open in new window

NOTE: You probably will have to set it back to


Open in new window

or whatever your default setting is
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 34971316
No luck.
Any other thoughts?
LVL 13

Accepted Solution

gamarrojgq earned 250 total points
ID: 34971368

Probably your Datagridview1 is not the first control in the Tab Order, so, use sendkeys to send TABs to get to your Datagridview.

Assuming that your datagridview1 is Second in the Forms Tab Order you can put this code in you FORM_ACTIVATE event

        Static blnSecondTime As Boolean
        If Not blnSecondTime Then
            DataGridView1.CurrentCell = DataGridView1.Item(2, 0)
            blnSecondTime = True
        End If

This will show you the cursor in the cell, the blnSecondTime variable will prevent the code to run again every time your form is focused.

Since you are using F2 with sendkeys, you do not have to change your EditMode DataGridViewEditMode.EditProgrammatically

Assisted Solution

barrislb earned 250 total points
ID: 34983221
Hi StoneCutter3,

Try putting your code into the form's 'Shown' event. Something like this:
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
   DataGridView1.CurrentCell = DataGridView1.Item(0, 0)
   DataGridView1.EditMode = Windows.Forms.DataGridViewEditMode.EditOnKeystrokeOrF2
End Sub

Open in new window

I hope this help you a little. :-)

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 49
VB 2005 Tooltips on Form Load Event 15 34
VB: Convert 2 dates to specific format 24 53
DataGridView / get bound table name? 8 28
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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