下面的示例代码展示了如何使用 GridView.CalcHitInfo 方法识别位于特定点的元素。
在本示例中,当鼠标移过网格控件时,调用了 CalcHitInfo 方法。 当前视图元素的名称被显示在窗体的标题中。
C# | 复制代码 |
---|---|
using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Base.ViewInfo; using DevExpress.XtraGrid.Views.Grid.ViewInfo; // ... private void gridControl1_MouseMove(object sender, MouseEventArgs e) { // Get a View at the current point. BaseView view = gridControl1.GetViewAt(e.Location); // Retrieve information on the current View element. BaseHitInfo baseHI = view.CalcHitInfo(e.Location); GridHitInfo gridHI = baseHI as GridHitInfo; if (gridHI != null) Text = gridHI.HitTest.ToString(); } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraGrid.Views.Base.ViewInfo Imports DevExpress.XtraGrid.Views.Grid.ViewInfo ' ... Private Sub GridControl1_MouseMove(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles GridControl1.MouseMove ' Get a View at the current point. Dim view As BaseView = gridControl1.GetViewAt(e.Location) ' Retrieve information on the current View element. Dim baseHI As BaseHitInfo = view.CalcHitInfo(e.Location) Dim gridHI As GridHitInfo = TryCast(baseHI, GridHitInfo) If Not gridHI Is Nothing Then Text = gridHI.HitTest.ToString() End If End Sub |