Solved

How to display the cursor in a datagridview

Posted on 2011-02-24
6
1,125 Views
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,
datagridview1.currentcell=datagridview1.item(0,0)
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?
Thanks.
0
Comment
Question by:StoneCutter3
6 Comments
 
LVL 17

Expert Comment

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

Author Comment

by:StoneCutter3
ID: 34970273

I tried with no luck.

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

Do you have an example?
Thanks.
0
 
LVL 17

Expert Comment

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

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

Open in new window


NOTE: You probably will have to set it back to

DataGridViewEditMode.EditOnKeystrokeOrF2

Open in new window


or whatever your default setting is
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

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

Accepted Solution

by:
gamarrojgq earned 250 total points
ID: 34971368
Hi,

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
            SendKeys.Send("{TAB}")
            DataGridView1.CurrentCell = DataGridView1.Item(2, 0)
            SendKeys.Send("{F2}")
            SendKeys.Send("{HOME}")
            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
0
 
LVL 4

Assisted Solution

by:barrislb
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
   DataGridView1.BeginEdit(True)
End Sub

Open in new window

I hope this help you a little. :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

12 Experts available now in Live!

Get 1:1 Help Now