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.
上面是在国外站点上的说明。我和一个同事在项目中也遇到类似的问题,VO类中要是有个属性名为uid,那么以这个VO列表作为数据源的Datagrid怎么选也不会选中行。
分享到:
相关推荐
3. **全选/全不选逻辑** - 在CheckBox_Checked事件处理函数中,遍历DataGrid的所有行,设置它们的IsSelected属性。 ```csharp private void CheckBox_Checked(object sender, RoutedEventArgs e) { var isChecked...
总结来说,删除`DataGridView`中选中行的关键在于正确处理`IsNewRow`属性,确保不误删未保存的新数据。通过以上的方法,我们可以高效且无误地实现这一功能,提高程序的用户体验。同时,理解并运用好`DataGridView`的...
它有三种状态:选中、未选中和不确定。 7. ChildWindow:ChildWindow是一个模态窗口,可以在主窗口之上弹出,阻止用户与主窗口的交互,常用于对话框或设置界面。 8. ComboBox:ComboBox结合了文本框和下拉列表,...
实例273 使用内连接选择一个表与另一个表中行相关的所有行 9.14 外连接查询 实例274 LEFT OUTER JOIN查询 实例275 RIGHT OUTER JOIN查询 实例276 使用外连接进行多表联合查询 9.15 利用IN进行查询 实例277 ...
实例273 使用内连接选择一个表与另一个表中行相关的所有行 9.14 外连接查询 实例274 LEFT OUTER JOIN查询 实例275 RIGHT OUTER JOIN查询 实例276 使用外连接进行多表联合查询 9.15 利用IN进行查询 实例277 ...
cc实例067 带复选功能的树状结构 cc实例068 显示磁盘目录 cc实例069 树型提示框 2.7 RichEdit控件典型实例 cc实例070 利用RichEdit显示Word文档 cc实例071 利用RichEdit控件实现文字...
cc实例067 带复选功能的树状结构 cc实例068 显示磁盘目录 cc实例069 树型提示框 2.7 RichEdit控件典型实例 cc实例070 利用RichEdit显示Word文档 cc实例071 利用RichEdit控件实现文字...
cc实例065 多级数据库树状结构数据显示 cc实例066 可动态修改节点的树状结构 cc实例067 带复选功能的树状结构 cc实例068 显示磁盘目录 cc实例069 树型提示框 2.7 RichEdit控件典型实例 cc实例070 利用...