开发者

Windows Forms application: help text on a grid view

I am working on a Windows application in C# using a DataGridView. How do I add a help text to appear when the u开发者_Go百科ser 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";
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜