Reputation: 348
I have one gridview in my windows form. Now i'm showing custom tooltip using the following code,
private void Audit_Dg_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 7 || e.ColumnIndex == 8 || e.ColumnIndex == 10 || e.ColumnIndex == 11 && e.RowIndex >= 0)
{
DataGridViewCell cell = this.Audit_Dg.Rows[e.RowIndex].Cells[e.ColumnIndex];
cell.ToolTipText = "Click Here To View The Message";
}
}
it showing my message for those cells satisfying my condition and the cell content for all those doesn't satisfying my condition. is there any way to remove that tool-tips from my grid-view and show only my custom tool-tip? if there any way,please help me...
Upvotes: 4
Views: 3872
Reputation: 11
As pointed out in the previous answer, the default tooltip is shown when a tooltip is not set and the column is not wide enough to display the cell text. The default tooltip can be avoided by making the column wide enough to display the text or by hooking up a CellFormatting-event and providing a text that fits the column, e.g.
private void grd_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
switch (e.ColumnIndex)
{
case 7:
case 8:
e.Value = string.Empty;
e.FormattingApplied = true;
break;
}
}
Upvotes: 1
Reputation: 263047
Unfortunately, the DataGridView
control does not support this. Its ShowCellToolTips property can only be used to disable tooltips globally. The cases where a tooltip is displayed are documented as:
The value of the
DataSource
property is notnull
or the value of theVirtualMode
property istrue
, and a handler for theCellToolTipTextNeeded
event sets theDataGridViewCellToolTipTextNeededEventArgs.ToolTipText
property to a value other thanString.Empty
.The
ToolTipText
property of the cell has a value other thanString.Empty
. Setting this property has no effect when there is aCellToolTipTextNeeded
event handler because getting the value of the property automatically raises the event and returns the ToolTip text specified in the event handler.The cell value is truncated in the cell display. When the value of the cell
ToolTipText
property value isString.Empty
, the full value of the truncated cell value is displayed in the ToolTip.
As you can see, there is no way to avoid the third case: If ShowCellToolTips
is true
and the value of a cell is truncated, a tooltip containing the full value will be displayed.
Upvotes: 3