你的位置:首页 > ASP.net教程

[ASP.net教程]DevExpress ToolTipController实现工具提示控件


1.定义一个ToolTipController变量   private ToolTipController _mToolTipController = null;

2.封装在一个方法中

protected void ToolTipController(GridControl gcData)
{
if (_mToolTipController == null)
{
_mToolTipController = new ToolTipController();
}
if (_mToolTipController == null) return;
if (gcData != null)
gcData.ToolTipController = _mToolTipController;
_mToolTipController.GetActiveObjectInfo += toolTipController_GetActiveObjectInfo;//绑定一个事件
}

//事件方法

private void toolTipController_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
{
GridControl gc = e.SelectedControl as GridControl;
if (gc == null) return;
ToolTipControlInfo info = null;
try
{
GridView view = gc.GetViewAt(e.ControlMousePosition) as GridView;
if (view == null) return;
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
if (hi.InRowCell)
{
info = new ToolTipControlInfo(new CellToolTipInfo(hi.RowHandle, hi.Column, "cell"), GetCellHintText(view, hi.RowHandle, hi.Column));
return;
}

if (hi.HitTest == GridHitTest.RowIndicator)
{
info = new ToolTipControlInfo(GridHitTest.RowIndicator.ToString() + hi.RowHandle.ToString(), "Row Handle: " + hi.RowHandle.ToString());
return;
}
}
catch (Exception ex)
{
WriteExceptionLog(ex);
}
finally
{
if (info != null) e.Info = info;
}
}

//提示信息

private string GetCellHintText(GridView view, int rowHandle, GridColumn gridColumn)
{
string displaytext = view.GetRowCellDisplayText(rowHandle, gridColumn);
displaytext = "提示信息";
return displaytext;
}

3.调用

ToolTipController(gcData);//gcData为列表控件

鼠标移动到每个单元格都会出现提示: