views:

1391

answers:

8

I have data bound DataGridView in a desktop app with columns that have their ToolTipText property set, yet no tool tip is displayed when I hover over grid view (cells or cell headers).

The ShowCellToolTips property of the grid view is 'true', and I have verified using break points that it is not changed programatically before I mouse over.

I have tried creating a CellToolTipTextNeeded event handler to see what the tool tip text was, but the event handler is never called.

Is there anything I have missed?

Thanks, Rob

Edit: We're using framework 2.0.

A: 

I don't know if this tip is a solution to your specific problem, but do you use SP1 of VS2008 ? This Service Pack resolves many different issues, as I have discovered.

FunnyBoy
@WunderWuzzi. No we don't have SP1 installed. I'll talk to the technical lead on the project to see if that's something we can try.I'll update the issue then. Thanks so much.
Robert Gowland
+1  A: 

It appears from your question that you set the tooltip text of the columns. Columns tooltip text only appears when floating over the headers. To show tooltip text on the cells you have to hookup the CellToolTipTextNeeded event and set the value of e.ToolTipText in the event args

Thanks for the reply, but as stated in the question:a) the tooltip text is not showing on the headers eitherb) the CellToolTipTextNeeded event handler is not firing
Robert Gowland
+1  A: 

We ended up using a ToolTip widget and the CellMouseEnter, CellMouseLeave events to show it appropriately. Not optimal, but it works around the odd behaviour we were experiencing.

Robert Gowland
A: 

You can also use Jquery for accessing and changing gridview cell, cell headers with jQuerys hover function. Just use

$('tbody tr').hover(function(){  //or 'tbody td'
   //now you can change and show your title or custom title
}, function() {
   //change back to old style
});

For detailed intruduction, look at this tutorial

http://net.tutsplus.com/tutorials/javascript-ajax/using-jquery-to-manipulate-and-filter-data/

fyasar
Thanks, fyasar, but it's a desktop app (see question), so Jquery isn't going to be of much help to me.
Robert Gowland
Ops, sory i didn't read correctly. Thanks for your notification.
fyasar
A: 

Try using Cell.ToolTipText property. You will probably need to loop the rows of the DataGridView and set the tooltips manually:

 For Each row As DataGridViewRow In Me.DataGridView.Rows
   Me.DataGridView("MyCol", row.Index).ToolTipText = "MyToolTipText"
 Next

Might not be suitable for a bound DataGridView with lots of rows but works successfully for me with an unbound DataGridView with a couple of hundred rows. Hope this helps.

Simon
A: 

I'm currently experiencing the same behvoiur on Framework 3.5. Is seems the DataSource property needs to be set in order to get the CelToolTipTextNeeded event to fire.

sindre j
@sindre In my case, the DataSource is definitely set, otherwise there would be no data in my GridView.
Robert Gowland
+1  A: 

When I added a datagridview with a single (empty) column to a form, added text to the ToolTipText property for that column, and ensured that the ShowCellToolTips property for the datagridview is set to True, I do get a tooltip popup when I hover my mouse over that column's header. This seems to contradict what was stated in the original question, but in my test the grid was not data bound. Not sure if that makes a difference. However, on a project with a data bound datagridview, I just used a ToolTip component:

(1) Add a ToolTip component to your form.
(2) Set the ToolTip on toolTip1 (or equivalent name for your ToolTip component) property for your datagridview to whatever text you want to display.
(3) Set your datagridview's ShowCellToolTips property to False.
(4) Viola! Works as expected.

Nick
A: 

I found this article looking for help on setting tooltips per row.

I just wanted to confirm that handling the CellToolTipText event works for me in VS2008 SP1.

For those of you who are wondering how the set the text to a value from the underlying datarow, this might be useful:

    private void myDGV_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e)
    {
        // This is used to set tooltiptext for individual cells in the grid.
        if (e.ColumnIndex == 2)  // I only want tooltips for the second column (0-based)
        {
            if (e.RowIndex >= 0)   // When grid is initialized rowindex == 0
            {
                // e.ToolTipText = "this is a test."; // static example.

                DataRowView drv = ((DataGridView)sender).Rows[e.RowIndex].DataBoundItem as DataRowView;
                MyTableRowClass theRow = drv.Row as MyTableRowClass;
                e.ToolTipText = theRow.Col1  + "\r\n" + theRow.Col2;
            }
        }
    }
shindigo
This might be a better way to test for the correct column. It will still work if you re-arrange the order of the columns.if(myDGV.Columns[e.ColumnIndex].Name == "MyColumn")
shindigo