c# - 禁用某些单元格的工具提示

标签 c# winforms datagridview tooltip

我的窗口窗体中有一个 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 not null or the value of the VirtualMode property is true, and a handler for the CellToolTipTextNeeded event sets the DataGridViewCellToolTipTextNeededEventArgs.ToolTipText property to a value other than String.Empty.

  • The ToolTipText property of the cell has a value other than String.Empty. Setting this property has no effect when there is a CellToolTipTextNeeded 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 is String.Empty, the full value of the truncated cell value is displayed in the ToolTip.

如您所见,无法避免第三种情况:如果 ShowCellToolTipstrue 并且单元格的值被截断,则工具提示包含完整的值显示。

关于c# - 禁用某些单元格的工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12854293/

相关文章:

c# - MimeKit.MimeMessage 到浏览器可渲染的 HTML

c# - 在 Windows 窗体 (c#.net) 应用程序中加速从磁盘加载图像

winforms - 在选择更改时直接应用和验证绑定(bind)的 DataGridViewComboBoxCell

c# - 使用 DataGridViewImageColumn 将图像添加到 DataGridView

c# - 如何使 DataGridView.Rows.DividerHeight 工作?

c# - 在我们正在实现的每个方法中使用#region 是否好

c# - 使用最小起订量 : mock object throwing 'TargetParameterCountException'

c# - 安全上传/下载文件,winforms c# 和 asp.net

C# 创建自定义控件

c# - 使用列表(多个值)过滤绑定(bind) Datagridview