Solved

DataGridView: How to place button in leftmost column's header cell?

Posted on 2006-07-01
1
363 Views
Last Modified: 2008-01-16
Hello,

I have a DataGridView and I would like to place a button in the leftmost column's header cell.  This button will be clicked by a user to insert a new record in the DGV rather than using the DGV's usual features.  Each row, has  "Delete" and "Edit" buttons, which work perfectly.  Anyway, I have scoured the forums and Googled, but have only found the following reference that provides some information about programming this idea:

 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=134933&SiteID=1

Unfortunately, it didn't work.  The instructions said to subclass the DGV, override the OnMouseClick method, and look for when the "Row and Column index values are -1".  There is only one parameter to the method and it does not contain these fields...  The closest matches are X and Y and Location.X and Location.Y, and these fields never contained -1 when I clicked the header cell...  It seems to me that others must have accomplished placing a button in this location... HELP!!!  Currently, I have placed an "Insert" button on the form, but it would be much more meaningful in the location that I have mentioned...  Closer to the context of the operation to be performed on the DGV.

Thanks in advance for any and all ideas!

Mike
0
Comment
Question by:mjgardne
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17026074
Here is the culprit:

Private Sub OnTopLeftHeaderMouseDown()
      If Me.MultiSelect Then
            Me.SelectAll
            If (-1 <> Me.ptCurrentCell.X) Then
                  Me.SetCurrentCellAddressCore(Me.ptCurrentCell.X, Me.ptCurrentCell.Y, False, False, False)
            End If
      End If
End Sub

One possibility would be to place a control, like a Button over that region, so that a mouse click can't occur in that cell.

Bob
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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