DevExpress GridView column Header click event

Source: Internet
Author: User

The GridView has a Rowcellclick event, which is a cell click event, but there are no corresponding events for column header rows and column header cells.

The MouseDown event of the GridView is used here. It also uses Gridhitinfo to get the click location information to determine if it is on the column header. Gridhitinfo gets information about the point based on the X and Y coordinates of the mouse click, and determines whether to click within the column header row.

private void Gridview_mousedown (object sender, MouseEventArgs e) {//left mouse button click if (E. Button= = MouseButtons. Left) {Gridhitinfo info = GridView. Calchitinfo(E. XE. Y);In the column title bar and the column header name is"ColName"if (info. Incolumnpanel&& Info. Column. Name=="ColName") {Xtramessagebox. Show("Click on the Name column heading! ");}            }        }

The above code is simple, but there is a small problem, that is, the column to the right line to drag the column width, the dialog box will also pop up, because dragging the column width here is also considered a mouse click. This is obviously inappropriate. The solution to this problem is also very simple, is to determine the mouse click position is not in the right edge to the left to move a little distance (3 pixels) in the range. The above code is slightly modified below, there will be no more this problem.

private void Gridview_mousedown (object sender, MouseEventArgs e) {//left mouse button click if (E. Button= = MouseButtons. Left) {Gridhitinfo Gridhitinfo = GridView. Calchitinfo(E. XE. Y);In the column title bar and the column header name is"ColName"if (gridhitinfo. Incolumnpanel&& Gridhitinfo. Column. Name=="ColName") {//Gets the right line of the columnxCoordinate gridviewinfo Gridviewinfo = (gridviewinfo) This. GridView. Getviewinfo();Intx= Gridviewinfo. Getcolumnleftcoord(Gridhitinfo. Column) + Gridhitinfo. Column. Width;Right edge move Left3Pixel position does not pop up the dialog box (experimental proof3Pixel is the right one) if (E. X<x-3) {Xtramessagebox. Show("Click on the Name column heading! ");}                }            }        }

The above method is reproduced from: DevExpress GridView using the column header click event
Method Two (colleague Hao brother wanted to come out):

if (info.InColumnPanel){                    if (gridControl1.Cursor != Cursors.Default)    {        XtraMessageBox.Show("当鼠标在标题栏两列之间的时候,鼠标的样式会发生变化");    }    else    {        //这里面应该是点击的列标题而不是两列之间的那部分    }}

Jiankunking Source: http://blog.csdn.net/jiankunking

DevExpress GridView column Header click event

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.