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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

Change click behavior on DataGridView cell

In a DataGridView, when the user wants to edit a text cell, it requires 3 clicks: one to select the cell, one to put it into edit mode (with whole cell highlighted) and one to remove highlighting and put the pointer at the clicked character.

I know how to add an event handler so that I can get the clicked cell. But what do I do next?
0
BlearyEye
Asked:
BlearyEye
2 Solutions
 
mkobrinCommented:
I'm not sure if this the best option for you, but one way is to create a textbox dynamically on your click event, size it to the same size as the cell, populate it with the contents of the cell , and then position it exactly where the cell is, and on the leave event of the textbox, update the contents of the cell with the contents of the textbox, before hiding or disposing of the textbox. Be sure to handle a cancel option for the user.
0
 
BlearyEyeAuthor Commented:
My question was incomplete but mkobrin got the idea: I want to reduce this to a single click.

The textbox suggestion sounds complex and error-prone ...
0
 
kris_perCommented:

You need to sub-class DataGridView and handle the mouse down message for this. Code for OneClickEditDataGridView class is here =>
http://social.msdn.microsoft.com/Forums/en/winformsdatacontrols/thread/8004651f-80a4-4b36-bb56-1518aea66b73

Hope this helps.
0
Industry Leaders: 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!

 
ZhaolaiCommented:
In the CellClick event, add BeginEdit(), like this:

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        DataGridView1.BeginEdit(False)
    End Sub

Open in new window

0
 
BlearyEyeAuthor Commented:
Zhaolai: that reduces it to two mouse clicks (one to select & enter edit mode without selection and another to position the cursor). But it is a lot less confusing than the default.

I found this link on MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.beginedit.aspx
That's a lot more complex than your proposal. Any thoughts on the difference?
0
 
BlearyEyeAuthor Commented:
Zhaolai's solution pointed me in the right direction but it was incomplete and I came up with the correct reference after that.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now