如何在GridLookUpEdit中显示工具提示?

时间:2014-09-08 12:31:05

标签: c# devexpress

我有一个GridLookUpEdit控制器和ToolTipController,想在FocusedRowChanged事件中显示GridLookUpEdit行的工具提示。
但是我找不到任何例子 我已经尝试过:

toolTipController1.SetToolTip(MyGridLookUpEdit, "Test");

但工具提示未显示。

private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
    {
      ToolTipControlInfo info = null;
      GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
      object o = hi.HitTest.ToString() + hi.RowHandle.ToString();
      string text = "Row " + hi.RowHandle.ToString();
      info = new ToolTipControlInfo(o, text);
      if (info != null)
        e.Info = info;
    }

同样的结果。
什么可能是错的?

2 个答案:

答案 0 :(得分:2)

您需要将ToolTipController附加到GridControl的基础GridLookUpEdit

gridLookUpEdit1.Properties.View.GridControl.ToolTipController = toolTipController1;

然后您可以使用ToolTipController.GetActiveObjectInfo事件来显示工具提示。要获得重点值,您可以使用ColumnView.GetFocusedRowCellValue方法或GridView.GetFocusedValue方法 这是一个例子:

private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
    var gridControl = gridLookUpEdit1.Properties.View.GridControl;

    if (e.SelectedControl == gridControl)
    {
        var view = gridControl.GetViewAt(e.ControlMousePosition) as GridView;

        if (view != null)
        {
            object focusedValue = view.GetFocusedRowCellValue(view.Columns[0]);

            if (focusedValue != null)
                e.Info = new ToolTipControlInfo(view.FocusedRowHandle, focusedValue.ToString());
        }
    }
}

答案 1 :(得分:1)

首先确保您已连接控制器

MyGridLookUpEdit.ToolTipController = toolTipController1;

然后试试这个

private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
  GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
  if (hi.InRowCell)
  {
    string text = "Row " + hi.RowHandle.ToString();
    e.Info = new ToolTipControlInfo(hi.RowHandle, text);
  }
}