65.9K
CodeProject is changing. Read more.
Home

Show cell value as tool tip for a Windows Form Grid

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Aug 23, 2011

CPOL
viewsIcon

19620

How to show the cell value as a tool tip for a Windows Form Grid.

To show a tool tip, add an event handler for the CellToolTipTextNeeded event and add the code below (depending on your requirement):

private void gridView1_CellToolTipTextNeeded(object sender, 
    DataGridViewCellToolTipTextNeededEventArgs e)
{
    if (e.ColumnIndex == 0)
        e.ToolTipText = "PrintPreview";
    else if (e.ColumnIndex == 1)
        e.ToolTipText = "Print";
    else if (e.ColumnIndex == 2)
        e.ToolTipText = "delete the file";
    else
        e.ToolTipText = string.Format("{0}", 
            gridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
}