【发布时间】:2011-05-15 09:55:45
【问题描述】:
我正在使用 DataGridView 在 C# 中开发一个 Windows 应用程序。如何添加帮助文本以在用户将鼠标悬停在列上时显示?
【问题讨论】:
标签: c# .net datagridview
我正在使用 DataGridView 在 C# 中开发一个 Windows 应用程序。如何添加帮助文本以在用户将鼠标悬停在列上时显示?
【问题讨论】:
标签: c# .net datagridview
使用 DataGridView 的 ToolTip 属性。
一篇非常好的文章是How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control。这是你想要的。以下是示例代码。
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
&& e.Value != null )
{
DataGridViewCell cell =
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (e.Value.Equals("*"))
{
cell.ToolTipText = "very bad";
}
else if (e.Value.Equals("**"))
{
cell.ToolTipText = "bad";
}
else if (e.Value.Equals("***"))
{
cell.ToolTipText = "good";
}
else if (e.Value.Equals("****"))
{
cell.ToolTipText = "very good";
}
}
}
【讨论】: