Solved

How to display the cursor in a datagridview

Posted on 2011-02-24
6
1,171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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