Solved

DataGridView - programatically hit the F2 key

Posted on 2006-07-09
6
1,130 Views
Last Modified: 2008-02-01
In the DataGridView my code is adding a new row, after I do this I would like to go ahead and place the cursor inside the first cell so that the user can start editing its value. How can I do this?

(I want to accomplish the same effect as if the user clicked into the cell or hit the F2 key to begin editing it). I'm trying to save the user from having to take this step.

Also, when a user begins typing a new blank row is autogenerated at the bottom. I want to make sure that this new row appears (otherwise it causes problems for my program).

-Joseph
0
Comment
Question by:brokeMyLegBiking
  • 3
  • 2
6 Comments
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 17069117
I figured out how to programatically beginEdit on a cell:

            dataGridView1.CurrentCell = dataGridView1.Rows(dataGridView1.Rows.Count - 1).Cells(0);
            dataGridView1.BeginEdit(false);

Now I just have to solve the second part of my question.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17069123
0
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 17069151
That was interesting, but that doesn't qute solve the 2nd issue.

Perhpas if I programmatically send a key to the cell after I put it in edit mode? Is there an easy way to programmatically press a key so that the new row appears? Or is there a better way to make that pesky new row appear?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17069221
does this help?

void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
   Grid.FirstDisplayedCell = Grid.Rows[e.RowIndex].Cells[0];
}
0
 
LVL 2

Expert Comment

by:TheUnkind
ID: 17077903
try this one

Datagridview1.AllowUserToAddRows = True
0
 
LVL 4

Author Comment

by:brokeMyLegBiking
ID: 17077926
I solved the issue, by just setting the allowusertoAddRows to false and adding a button. That takes the uncertainty out of it.

-Joseph
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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