• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

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

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
mjgardne
Asked:
mjgardne
1 Solution
 
Bob LearnedCommented:
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

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.

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