Solved

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

Posted on 2006-07-01
1
359 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now