我的Windows窗体中有一个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";
}
}
它显示了有关满足我条件的那些单元格的消息,而所有不满足我条件的那些单元格的内容.有什么方法可以从我的网格视图中删除该工具提示并仅显示我的自定义工具提示?
如果有什么办法,请帮助我…
解决方法:
不幸的是,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并且单元格的值被截断,则将显示包含完整值的工具提示.