Alex Rivera | Logout

Showing tool tip for every item in datagridview row when mouse is above it

Asked 2011-08-24T09:49:37.817
35

How can you show the tooltip for datagridview for every item in datagridview when you hover mouse over the item in that particular row?

I have table product with columns:

product name 
product price 
product description
product image ....

I have a requirement that I have a datagridview with columns and I am getting these from database:

product name 
product price 
product image ....

Now I want to show the tooltip like this: if I have mouse over the product image, the product description will be displayed for that product. I want to do this for every row. Would anyone please help on this one?

Edit
Report

2 Answers

8

I have done this by storing the text to show in the tooltip for each cell in the Tag property of each DataGridViewCell.

Then in the DataGridView.CellMouseEnter event you can see in which cell the mouse is using the DataGridViewCellEventArgs.ColumnIndex and DataGridViewCellEventArgs.RowIndex values and set the text from the corresponding cell as the tooltip text using ToolTip.SetToolTip.

If works pretty well.

Something like this:

private void dgv_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex >= 0 & e.RowIndex >= 0) 
    {
        ToolTip1.SetToolTip(dgv, Convert.ToString(dgv.Item(e.ColumnIndex, e.RowIndex).Tag));
    }
}
answered 2011-08-24T10:21:43.383
5

When filling the datagridview, just set the TooltipText property of the cell to the text you want to display.

answered 2012-07-25T05:56:13.380

Your Answer