如何在选择单元格时显示datagridview的工具提示,而不是使用鼠标悬停而使用箭头键?选择datagridview单元格时显示工具提示
3
A
回答
7
正如您已经注意到的,您将无法使用DataGridView的内置工具提示。实际上,您需要将其禁用,因此请将DataGridView的ShowCellToolTips
属性设置为false
(默认情况下为true
)。
您可以将DataGridView的CellEnter
事件与常规的Winform ToolTip控件一起使用,以显示工具提示,因为焦点在每个单元格之间变化,而不管这是使用鼠标还是箭头键完成的。
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) {
var cell = dataGridView1.CurrentCell;
var cellDisplayRect = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
toolTip1.Show(string.Format("this is cell {0},{1}", e.ColumnIndex, e.RowIndex),
dataGridView1,
cellDisplayRect.X + cell.Size.Width/2,
cellDisplayRect.Y + cell.Size.Height/2,
2000);
dataGridView1.ShowCellToolTips = false;
}
请注意,我根据单元格的高度和宽度向工具提示的位置添加了偏移量。我这样做了,所以ToolTip不会直接显示在单元格上;你可能想调整这个设置。
-1
dgv.CurrentCellChanged += new EventHandler(dgv_CurrentCellChanged);
}
void dgv_CurrentCellChanged(object sender, EventArgs e)
{
// Find cell and show tooltip.
}
0
Jay Riggs'answer是我用过的。另外,因为我需要更长的持续时间,所以我必须添加此事件才能使工具提示消失。
private void dataGridView_MouseLeave(object sender, EventArgs e)
{
toolTip1.Hide(this);
}
相关问题
- 1. 如何在显示DataGridView单元格时刷新工具提示?
- 2. Datagridview单元格工具提示延迟时间
- 3. 在C#中验证单元格并显示datagridview的气球工具提示
- 4. 显示DataGridView中的rowHeader工具提示
- 5. 如何在DataGridView单元格中为工具提示设置autoPopDelay?
- 6. Datagridview单元格工具提示自动换行
- 7. 如何显示每个单元格的工具提示?
- 8. 在JTable的单元格上方显示工具提示
- 9. 单元格上的工具提示。 GWT
- 10. WPF Datagrid单元格工具提示
- 11. SlickGrid中的单元格工具提示
- 12. 如何在选择缩放时显示工具提示
- 13. 如何在每次在datagridview中选择单个单元格时显示消息?
- 14. 在DataGridView列调整大小时显示工具提示
- 15. DataGridView上的工具提示
- 16. 当工具提示显示时,“实时”更新小工具的工具提示
- 17. 当光标在ListView单元格上时如何显示工具提示?
- 18. DataGridView不显示单元格数据
- 19. Extjs在整个网格行显示工具提示insted的单元格基础
- 20. EXTJS:在网格单元格上显示自定义工具提示
- 21. 在一个datagridview中选择单元格会突出显示其他Datagridview中的单元格
- 22. 当选择时显示图像datagridview
- 23. 工具提示选择框选项
- 24. 如何在选择单元格时突出显示表格列
- 25. 选择表格单元格时显示邮件编辑器
- 26. 悬停时不显示工具提示
- 27. 在拖动时显示工具提示
- 28. 选择隐藏或显示基于bool的工具提示
- 29. JQuery工具提示选择嵌套Div显示问题
- 30. 显示工具提示当移动在选择
嘿,这很好。非常感谢。 – TroyS
重要提示:您必须将“ShowCellToolTips”属性设置为“False”。我知道答案中已经说明了这一点,但我认为应该更加重视。 – Nepaluz