Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable tooltips for an entire .net DataGridView column

I have a winform datagridview which contains a column of buttons. I'd like to disable tooltips for that column only -- tooltips should still show up for other columns. I find tooltips get in the way of clicking the button -- when one clicks on the tooltip, the click event doesn't percolate down to the button. Very annoying.

I've tried handling the CellTooltipNeeded event and return null or empty string for that column, but then the tooltip just reverts to showing the button text in the tooltip. I've also tried setting the Column.ToolTipText to empty string, and that correctly hides the column header's tooltip, but all the other rows' tooltip still shows up.

What's the best way to disable tooltips for an entire column?

Thanks Jimmy

like image 831
Jimmy Avatar asked Oct 21 '25 02:10

Jimmy


1 Answers

I was looking for an answer to this question but all forums stated it was not possible. However, I did find a solution.

On your DataGridView, handle the CellMouseEnter event. In the event handler the DataGridViewCellEventArgs contains a ColumnIndex property. Use that to set the DataGridView.ShowCellToolTips property. Like this (Excuse the VB please):

Private Sub MyDataGridView_CellMouseEnter(sender As Object, e as DataGridViewCellEventArgs) Handles DataGridView.CellMouseEnter
    MyDataGridView.ShowCellToolTips = e.ColumnIndex = <the Column # I want to show Tooltips>
End Sub

And, obviously, it's very straightforward to turn this on or off at the cell level too since DataGridViewCellEventArgs also contains a RowIndex property.

I'm only sorry I discovered an answer five years after this was posted!

like image 119
Mark K Avatar answered Oct 24 '25 07:10

Mark K