排序数据时,在数据绑定的DGV中保留DataGridViewRow.Tag属性 [英] Preserve DataGridViewRow.Tag property in databound DGV when sorting data
问题描述
是否有一种方法可以防止在对网格进行排序后立即使标签为空?
Is there a way to keep the tags from being nulled as soon as I sort the grid?
如果没有,那么Tag属性除非-databound用法?
If not, is the Tag property actually useful for anything except non-databound usage?
推荐答案
根据您的最后一个问题,您正在设置DataGridViewRow对象的Tag。而且很可能在排序操作期间重新创建它们。确保使用反射器,但是我将开始寻找解决方法。
Based on you last question, you are setting the Tag of DataGridViewRow objects. And they might very well be re-created during a Sort operation. Use reflector to make sure, but I would start looking for a workaround.
通常,Tag属性是不得已的选择。
In general, the Tag property is a last resort.
您可以使用 Dictionary< object,object>
将数据耦合到 dgvr.DataBoundItem
作为键。
You could use a Dictionary<object, object>
to couple your data to the dgvr.DataBoundItem
as key.
这篇关于排序数据时,在数据绑定的DGV中保留DataGridViewRow.Tag属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!