Solved

How to display the cursor in a datagridview

Posted on 2011-02-24
6
1,115 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
Comment Utility
use sendkeys to send F2 or call beginedit()
0
 

Author Comment

by:StoneCutter3
Comment Utility

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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:StoneCutter3
Comment Utility
No luck.
Any other thoughts?
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 250 total points
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

10 Experts available now in Live!

Get 1:1 Help Now