?
Solved

Detect right click in ListView ColumnHeader

Posted on 2006-05-19
3
Medium Priority
?
549 Views
Last Modified: 2008-01-09
I would like to detect a right click on a ListView ColumnHeader with the ultimate goal of showing a context menu showing a checklist of the columns and allowing the user to add or remove visible columns from the ListView.

The ListView ColumnClick event only responds to left click.

What can I do? - Searched all over and have found only scant references - seems as though an API call may be necessary.  Could I avoid with some sort of hittest?

Any example code or links would be helpful.

Thanks

0
Comment
Question by:rmirabelle
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
prakash_prk earned 1000 total points
ID: 16724154
try the sample code in the following link
      http://www.codeproject.com/cs/miscctrl/myListViewNoSize.asp
      
That article have an sample to handle double click event on the header control.
Change the wndproc method of HeaderControl class to the following
---------------------------------------------------------------------------------------------------------------------
protected override void WndProc(ref Message message)
{
      const int WM_LBUTTONDBLCLK = 0x0203;
      const int WM_SETCURSOR = 0x0020;
      const int WM_RBUTTONUP = 0x0205;
      bool callBase = true;

      switch ( message.Msg )
      {
      case WM_LBUTTONDBLCLK:                    
      case WM_SETCURSOR:
            if(parentListView.LockColumnSize)
            {
                  //Don't change cursor to sizing cursor.  Also ignore
                  //double click, which sizes the column to fit the data.
                  message.Result = (IntPtr)1;      //Return TRUE from message handler
                  callBase = false;            //Don't call the base class.
            } //if
            break;
            case WM_RBUTTONUP:
                  MessageBox.Show("Right click");            //Right button Click
                  break;
      } //switch

      if(callBase)
      {
            // pass messages on to the base control for processing
            base.WndProc( ref message ) ;
      } //if
} //WndProc()
---------------------------------------------------------------------------------------------------------------------

Regards
Prakash

0
 
LVL 1

Author Comment

by:rmirabelle
ID: 16725862
I'm surprised that I don't find readily available a ListView with column right click functionality - guess I'll have to write and submit one!
Thanks, you pointed me in the right direction.
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 16726855
:). thanks  rmirabelle
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 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