【发布时间】:2016-11-03 11:28:12
【问题描述】:
我想为 DataGrid 中的每一行(和每个单元格)添加工具提示。我怎样才能做到这一点?我已经尝试过 RowDataBound 和 CellFormating,但似乎我无法在我的代码中使用此示例(没有类似事件)
你有什么处理方法的想法吗?
【问题讨论】:
我想为 DataGrid 中的每一行(和每个单元格)添加工具提示。我怎样才能做到这一点?我已经尝试过 RowDataBound 和 CellFormating,但似乎我无法在我的代码中使用此示例(没有类似事件)
你有什么处理方法的想法吗?
【问题讨论】:
这是来自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
【讨论】: