我的窗口窗体中有一个 gridview。现在我使用以下代码显示自定义工具提示,
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";
}
}
它为满足我的条件的那些单元格显示我的消息,而所有那些不满足我的条件的单元格内容。有没有办法从我的 GridView 中删除该工具提示并仅显示我的自定义工具提示? 如果有什么办法,请帮助我...
最佳答案
很遗憾,DataGridView
控件不支持这一点。它的ShowCellToolTips属性只能用于全局禁用工具提示。显示工具提示的情况记录为:
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.
如您所见,无法避免第三种情况:如果 ShowCellToolTips
为 true
并且单元格的值被截断,则工具提示包含完整的值将显示。
关于c# - 禁用某些单元格的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854293/