在这里使用GridView的MouseDown事件。这里同样使用的是GridHitInfo来获取点击位置的信息,来判断是否在列标题上。GridHitInfo根据鼠标点击的x、y坐标获取该点的相关信息,判断是否点击在列标题行内。
private
void
gridView_MouseDown(
object
sender, MouseEventArgs e)
{
//鼠标左键点击
if
(e.Button == MouseButtons.Left)
{
GridHitInfo info = gridView.CalcHitInfo(e.X, e.Y);
//在列标题栏内且列标题name是"colName"
if
(info.InColumnPanel && info.Column.Name ==
"colName"
)
{
XtraMessageBox.Show(
"点击Name列标题!"
);
}
}
}
private
void
gridView_MouseDown(
object
sender, MouseEventArgs e)
{
//鼠标左键点击
if
(e.Button == MouseButtons.Left)
{
GridHitInfo gridHitInfo = gridView.CalcHitInfo(e.X, e.Y);
//在列标题栏内且列标题name是"colName"
if
(gridHitInfo.InColumnPanel && gridHitInfo.Column.Name ==
"colName"
)
{
//获取该列右边线的x坐标
GridViewInfo gridViewInfo = (GridViewInfo)
this
.gridView.GetViewInfo();
int
x = gridViewInfo.GetColumnLeftCoord(gridHitInfo.Column) + gridHitInfo.Column.Width;
//右边线向左移动3个像素位置不弹出对话框(实验证明3个像素是正好的)
if
(e.X < x - 3)
{
XtraMessageBox.Show(
"点击Name列标题!"
);
}
}
}
}