如何防止DataGridView共享行? [英] How do I prevent a DataGridView from sharing rows?

查看:54
本文介绍了如何防止DataGridView共享行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个自定义DataGridViewCell,它显示自定义控件而不是单元格;但是,如果DataGridView使用共享行,则自定义控件实例也会共享,因此您会得到奇怪的行为(例如,将鼠标悬停在按钮上会突出显示所有按钮).另外,我无法访问DataGridViewCell.Selected属性,所以我不知道该行用什么颜色绘制.

I've made a custom DataGridViewCell that displays a custom control instead of the cell; but if the DataGridView uses shared rows, then the custom control instance is also shared, so you get strange behaviour (for example, hovering over buttons highlights all the buttons). Also, I can't access the DataGridViewCell.Selected property, so I don't know what colour to paint the row.

如何防止DataGridView共享行?我知道我可以使用Rows.Add(object [])覆盖来添加行,但是第一行仍然是共享的(即索引为-1),因此颜色问题仍然存在.

How do I prevent a DataGridView from sharing rows? I know I can add the rows using the Rows.Add(object[]) override, but then the first row is still shared (i.e. has index -1) so the problem with colours still applies.

我需要能够告诉DataGridView不共享包含自定义单元格的行.可以使用属性来完成吗?可以做到吗?

I need to be able to tell the DataGridView not to share a row containing a custom cell. Can that be done with attributes? Can it be done at all?

推荐答案

尝试在行"的一个单元格中设置工具提示文本

Try to set a Tooltip Text in one cell of the Row

在以下任何一种情况下都不能共享行:该行包含一个不在选定列中的选定单元格.该行包含其ToolTipText或ContextMenuStrip属性设置的单元格.该行包含一个设置了Items属性的DataGridViewComboBoxCell.

A row cannot be shared in any of the following situations: The row contains a single selected cell that is not in a selected column. The row contains a cell with its ToolTipText or ContextMenuStrip properties set. The row contains a DataGridViewComboBoxCell with its Items property set.

或阅读

http://msdn.microsoft.com/en-us/library/ha5xt0d9.aspx

了解更多信息

这篇关于如何防止DataGridView共享行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆