解决DataGrid选不中某些行的办法
曾经在我的旧博客和经典上发表过一篇文章:为什么 DataGrid 不能选中字段值相同的项?(具体问题内容请点击进去查看)此问题如下所示,无论如何你都不能选中第一项:
一直在寻找答案的同时也等待着达人的解决。直到刚才,我在这个博客上找到了解决办法。那个博客的主人是在google上找到的,原文如下:
I have noticed a strange behavior of DataGrid and Tree classes. (This extends to every subclass of ListBase.) The behavior is that under certain circumstances you will only be able to select the first item in the DataGrid or Tree.
Before figuring out what was really going on, I empirically discovered two ways of working around this problem: the first is to ensure that all the objects contained by the DataGrid or Tree are dynamic (i.e., the class is declared as a public dynamic class). The second is to implement toString().
What’s actually going on is that the DataGrid and Tree classes are keeping track of their objects by using UIDUtil.getUID(). This function tries a bunch of different approaches to generate a UID for an object. At some point it tries to assign a “uid” property to the object, which fails if the object is not a dynamic class. Its last chance attempt in the exception handler is to use toString().
The first thing it tries, by the way, is to test the object to see if it implements IUID, and if it does, it just uses that interface’s uid property. I implemented IUID to verify this, and it does work. That interface’s get uid() function gets called a lot, so it’s probably worth it to do this on all objects that we display in ListBase subclasses.
评论
哦 原来是这样的呀
回复他(她)
Y.Boy Reply:
七月 21st, 2008 at 21:05
是的 就是这样的了
你恍然大悟了
回复他(她)
UID惹的祸?
回复他(她)
Y.Boy Reply:
七月 22nd, 2008 at 12:43
嗯..我也是看了那个才知道ListBase原来有UIDUtil.getUID()这玩意…
回复他(她)
发表评论