Solved

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

Posted on 2006-07-01
1
370 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
[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
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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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