Search code examples
c#.netdatagridtooltip

Tooltip over DataGrid row in C# .Net 4.0


I want to add tooltip for every row (and for every cell) in DataGrid. How can I do this? I've tried RowDataBound and CellFormating, but it seems that I can't use this examples in my code (no similar events)

Do you have any ideas how to handle it?


Solution

  • Here Is an Example From MSDN, In which they Clearly described how to Gets or sets the ToolTip text associated with this cell. with the help of _CellFormatting event of the control; Consider the code below:

    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";
        }
    }
    

    You can try Conditional Tooltips Too like this(this too explained in the associated link):

    if (e.Value.Equals("some value"))
    {
        cell.ToolTipText = "ToolTip 1";
    }
    else if (e.Value.Equals("some other value"))
    {
        cell.ToolTipText = "ToolTip 2";
    }
    // Like wise