I am working on a Windows application in C# using a DataGridView. How do I add a help text to appear when the user hovers over the columns?
Use the ToolTip property of DataGridView.
A very good article is How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control. It is what you want. Following is sample code.
// 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";
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With