C # how to add a right-click menu only in the header (column name) of the girgirdview Control

Source: Internet
Author: User

Recently, I have been working on arcgisae. One of the functions is to operate attribute fields of layers. To facilitate attribute operations of layers, it is best to be in the Attribute Table of layers, that is, in displaying layer attributes.DatagirdviewAdd a right-click menu to the control's header to implement the corresponding functions.

In C #, There is a shortcut menu set up.ContextmenustripIn this control, you can add some functions to process attribute fields, and then assign this controlDatagirdviewOfContextmenustripThe attribute can be used. However, in this wayDatagirdviewThe right-click menu of the control will be displayed anywhere, and the right-click menu will be displayed in the row and column, which will not achieve the expected effect.

As a result, you can view it on msdn at will.DatagirdviewVarious attributes and events have finally discovered a patchwork implementation method.DatagirdviewRight-click a column.

  DatagirdviewControl hasColumnheadermouseclickFor such an event, only clickDatagirdviewThis event is triggered only when the control header is where we want it, and this event also has a column index clicked on the column.

  The principle is as follows:

1. Do not useContextmenustripAttribute

2. ExploitationDatagirdviewControlColumnheadermouseclickEvent. The right-click menu is displayed as code at the place where the mouse clicks each time the event is triggered..

  The Code is as follows::

1. Add a shortcut menu control

2.DatagirdviewControlColumnheadermouseclickWrite the following code:

      

// Mousepostion is relative to the screen, and the show method of the right-click menu is relative to the screen coordinate // MessageBox. show (E. location. tostring (); If (E. button = mousebuttons. right) {// you can obtain the index int Index = E. columnindex; this. contextmenustrip1.show (mouseposition. x, mouseposition. Y );}

 

In this way, you can achieveDatagirdviewRight-click the header (column name) in the control.

      PS: There are several ways to get the mouse coordinates, but their specific meanings or the reference points are different.

1,MousepositionThe class has a static X and Y attributes. The obtained coordinates are relative to the coordinate origin of the screen, that is, the upper left corner.

2. Any mouse event of a control has a parameterE, EThere are two X and Y data. The coordinate is relative to the coordinate origin of the control.

3,CursorClass has a static propertyPositionRepresents the current position of the mouse.MousepositionThe method is the same, which is relative to the coordinate origin of the screen.

      

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.