Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to display the cursor in a datagridview

Posted on 2011-02-24
6
Medium Priority
?
1,207 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

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

Accepted Solution

by:
gamarrojgq earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

879 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