Windows Forms Application: grid help text

I am working on a Windows application in C # using a DataGridView. How to add help text when user hovers over columns?

+3
source share
1 answer

Use the ToolTipDataGridView property .

A very good article How to add tooltips to individual cells in a Windows Forms DataGridView control . Is this what you want. The 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";
        }
    }
}
+3
source

All Articles