Solved

Change click behavior on DataGridView cell

Posted on 2010-11-10
6
694 Views
Last Modified: 2012-05-10
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
Comment
Question by:BlearyEye
[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 7

Expert Comment

by:mkobrin
ID: 34100499
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
 
LVL 1

Author Comment

by:BlearyEye
ID: 34100731
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
 
LVL 16

Expert Comment

by:kris_per
ID: 34101125

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 500 total points
ID: 34104916
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
 
LVL 1

Accepted Solution

by:
BlearyEye earned 0 total points
ID: 34108250
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
 
LVL 1

Author Closing Comment

by:BlearyEye
ID: 34195074
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 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