如何为TreeList单元格自定义Tooltip

.Net技术 码拜 8年前 (2015-01-21) 2431次浏览 0个评论

How to customize the ToolTip for a TreeList cell

Yes, it’s possible. You should drop the ToolTipController onto a form, set the TreeList’s ToolTipController property and handle theToolTipController.GetActiveObjectInfo event.
[C#]
using DevExpress.XtraTreeList;

using DevExpress.XtraTreeList.ViewInfo;



private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) {

   if(e.SelectedControl is DevExpress.XtraTreeList.TreeList) {

       TreeList tree = (TreeList)e.SelectedControl;

       TreeListHitInfo hit = tree.CalcHitInfo(e.ControlMousePosition);

       if(hit.HitInfoType == HitInfoType.Cell) {

           object cellInfo = new TreeListCellToolTipInfo(hit.Node, hit.Column, null);

           string toolTip = string.Format("{0} (Column: {1}, Node ID: {2})", hit.Node[hit.Column], hit.Column.Caption, hit.Node.Id);

           e.Info =  new DevExpress.Utils.ToolTipControlInfo(cellInfo, toolTip);                    

       }

   }

}
[VB.NET]
Imports DevExpress.XtraTreeList

Imports DevExpress.XtraTreeList.ViewInfo



Private Sub toolTipController1_GetActiveObjectInfo(ByVal sender As Object, ByVal e As DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs) Handles toolTipController1.GetActiveObjectInfo

   If TypeOf e.SelectedControl Is DevExpress.XtraTreeList.TreeList Then

       Dim tree As TreeList = CType(e.SelectedControl, TreeList)

       Dim hit As TreeListHitInfo = tree.CalcHitInfo(e.ControlMousePosition)

       If hit.HitInfoType = HitInfoType.Cell Then

           Dim cellInfo As Object = New TreeListCellToolTipInfo(hit.Node, hit.Column, Nothing)

           Dim toolTip As String = String.Format("{0} (Column: {1}, Node ID: {2})", hit.Node(hit.Column), hit.Column.Caption, hit.Node.Id)

           e.Info = New DevExpress.Utils.ToolTipControlInfo(cellInfo, toolTip)

       End If

   End If

End Sub

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何为TreeList单元格自定义Tooltip
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!