【问题标题】:Showing a tooltip inside a datagrid在数据网格中显示工具提示
【发布时间】:2010-10-04 08:56:03
【问题描述】:

我正在尝试在数据网格中显示 Windows 窗体工具提示以突出显示错误。我遇到的问题是,每次我调用tooltip.Show("You have an error", datagrid, 0, 0) 时,工具提示都被限制在数据网格边界内并且不会向外,这最终意味着工具提示本身会覆盖发生错误的实际行。

我考虑过tooltip.Show("You have an error", Form1, ?, ?),但我没有看到一种简单的方法来计算表单上数据网格的偏移量。由于所有控件都停靠,根据用户调整表单大小的方式,位置会发生变化。

需要注意的是,数据网格本身不是 Forms.DataGrid,而是 Infragistics UltraGrid,它本身可能会做一些有趣的事情,这超出了我的能力范围。

【问题讨论】:

    标签: winforms datagrid tooltip


    【解决方案1】:

    事实证明,通过查询与其关联的 UIElement 从 UltraGrid 中获取 Show 命令的位置很容易。这就是我正在做的事情:

    private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e)
    {
        if (!DataFormat.CanEdit(e.Cell.Row.ListObject, e.Cell.Column.PropertyDescriptor))
        {  
            var tip = new System.Windows.Forms.ToolTip();
            tip.BackColor = Color.Orange;
            tip.Show("unable to edit", this, e.Cell.GetUIElement().Rect.Left, e.Cell.GetUIElement().Rect.Top, 500);
            e.Cancel = true;
        }
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 我现在已经看过了,但是我使用tooltip.Show 来弹出一个不能轻易关闭的气球框(因为输入错误)。同时,我不希望它干扰输入。
      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 2014-12-08
      • 2018-10-25
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多