下面的示例展示了如何为 XtraGrid 控件中的行指示器单元格实现实现自定义工具提示。 缺省时,这个网格控件不支持行指示器单元格的工具提示。 要提供工具提示, 则把 ToolTipController 组件拖放到窗体中,把它指派到这个网格控件的 EditorContainer.ToolTipController 属性中,并接管 ToolTipController.GetActiveObjectInfo 事件。
在我们的示例中,这个工具提示将显示 "Row N" 文本,其中 N 是行的序号。
C# | 复制代码 |
---|---|
using DevExpress.Utils; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; //... private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e) { if(e.SelectedControl != gridControl1) return; ToolTipControlInfo info = null; //Get the view at the current mouse position GridView view = gridControl1.GetViewAt(e.ControlMousePosition) as GridView; if(view == null) return; //Get the view's element information that resides at the current position GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition); //Display a hint for row indicator cells if(hi.HitTest == GridHitTest.RowIndicator) { //An object that uniquely identifies a row indicator cell object o = hi.HitTest.ToString() + hi.RowHandle.ToString(); string text = "Row "+ hi.RowHandle.ToString(); info = new ToolTipControlInfo(o, text); } //Supply tooltip information if applicable, otherwise preserve default tooltip (if any) if (info != null) e.Info = info; } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Views.Grid.ViewInfo Private Sub ToolTipController1_GetActiveObjectInfo(ByVal sender As Object, _ ByVal e As DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs) _ Handles ToolTipController1.GetActiveObjectInfo If Not e.SelectedControl Is gridControl1 Then Return Dim info As ToolTipControlInfo = Nothing 'Get the view at the current mouse position Dim view As GridView = gridControl1.GetViewAt(e.ControlMousePosition) If view Is Nothing Then Return 'Get the view's element information that resides at the current position Dim hi As GridHitInfo = view.CalcHitInfo(e.ControlMousePosition) 'Display a hint for row indicator cells If hi.HitTest = GridHitTest.RowIndicator Then 'An object that uniquely identifies a row indicator cell Dim o As Object = hi.HitTest.ToString() + hi.RowHandle.ToString() Dim text As String = "Row " + hi.RowHandle.ToString() info = New ToolTipControlInfo(o, text) End If 'Supply tooltip information if applicable, otherwise preserve default tooltip (if any) If Not info Is Nothing Then e.Info = info End Sub |