简体   繁体   English

WinForms Datagridview:标记属性问题

[英]WinForms Datagridview: Tag property problem

I have a Winform datagridview , which is bind to a datatable. 我有一个Winform datagridview ,它绑定到一个数据表。 After loading the grid, I assign for every row an associated object to the Tag property . 加载网格后,我为每一行分配一个关联对象给Tag属性 The problem is now. 现在的问题是。 that after some actions/clicks all Tag properties are NULL again. 在执行某些操作/单击后,所有Tag属性再次变为NULL The cell values are still there. 单元格值仍然存在。 What could be the reason for that? 可能是什么原因呢?

The issue you're describing may be due to the way DataGridView attempts to "share" rows to conserve memory. 您正在描述的问题可能是由于DataGridView尝试“共享”行以节省内存的方式引起的。 You can read more about the behavior here: http://msdn.microsoft.com/en-us/library/ha5xt0d9.aspx 您可以在此处了解有关该行为的更多信息: http : //msdn.microsoft.com/zh-cn/library/ha5xt0d9.aspx

Various programmatic and user actions can cause a row to become unshared. 各种程序和用户操作可能导致行变得不共享。 From the docs it appears that this causes a new (unshared) row to be created. 从文档看来,这将导致创建新的(非共享)行。 If all of the rows were maintained as individual objects in the grid, you could potentially have significant performance issues. 如果所有行都作为网格中的单个对象维护,则可能会出现严重的性能问题。

Can you set the associated object on the underlying data item that the row is bound to? 您可以在该行绑定到的基础数据项上设置关联对象吗?

可能是您的数据源已更新或网格已重新绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM