Solved

How to display the cursor in a datagridview

Posted on 2011-02-24
6
1,130 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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