您如何将数据绑定到 System.Windows.Forms.Treeview 控件? [英] How do you databind to a System.Windows.Forms.Treeview control?
问题描述
我正在查看这个控件,它似乎缺少用于数据绑定的标准 .net数据源"和数据成员"属性.这个控件是不可绑定的吗?我想我可以编写一些自定义函数,从给定的数据源填充树视图,并根据需要嵌入数据对象,但这是最佳实践"吗?还是每个人都只是使用 3rd 方树视图控件?
您说得对,没有数据绑定.原因是 TreeView 是分层数据结构.也就是说,不是一个直接的列表.因此,databind 选项对于表示 List 结构是无效的.
遗憾的是,它正在创建您自己的填充方法或购买第 3 方控件(最终将拥有自己的填充方法.)
这是一篇关于绑定分层数据的不错的 MSDN 文章.>
I'm looking at this control, and it seems to be lacking the standard .net "datasource" and "datamember" properties for databinding. Is this control not bindable? I can write some custom function that populates the treeview from a given data source, I suppose, and embed data objects as necessary, but is that the 'best practice'? Or does everyone simply use a 3rd party treeview control?
You are correct in that there is no data binding. The reason being is that TreeViews are hierarchical data structures. That is, not a straight list. As a result the databind option is invalid to say a List structure.
Sadly it's creating your own populate methods or buying 3rd party controls (which in the end will have their own populate methods.)
Here's a decent MSDN article on Binding Hierarchical Data.
这篇关于您如何将数据绑定到 System.Windows.Forms.Treeview 控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!