【问题标题】:Tooltip over DataGrid row in C# .Net 4.0C# .Net 4.0 中 DataGrid 行的工具提示
【发布时间】:2016-11-03 11:28:12
【问题描述】:

我想为 DataGrid 中的每一行(和每个单元格)添加工具提示。我怎样才能做到这一点?我已经尝试过 RowDataBound 和 CellFormating,但似乎我无法在我的代码中使用此示例(没有类似事件)

你有什么处理方法的想法吗?

【问题讨论】:

    标签: c# .net datagrid tooltip


    【解决方案1】:

    这是来自MSDN 的示例,他们在其中清楚地描述了如何获取或设置与此单元格关联的工具提示文本。借助控件的_CellFormatting 事件;考虑下面的代码:

    void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if ((e.ColumnIndex == this.dataGridView1.Columns["column_name"].Index)  && e.Value != null)
        {
            DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
            cell.ToolTipText = "This is given ToolTip";
        }
    }
    

    你可以试试 Conditional Tooltips Too like this(这在相关链接中也有解释):

    if (e.Value.Equals("some value"))
    {
        cell.ToolTipText = "ToolTip 1";
    }
    else if (e.Value.Equals("some other value"))
    {
        cell.ToolTipText = "ToolTip 2";
    }
    // Like wise
    

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 2011-11-11
      相关资源
      最近更新 更多