你如何将数据绑定到一个System.Windows.Forms.Treeview控件?

问题描述:

我正在看这个控件,似乎缺少数据绑定的标准.netdatasource和datamember属性。这个控件是否无法绑定?我可以编写一些自定义函数,从给定的数据源填充树视图,我想,并根据需要嵌入数据对象,但那是最佳实践?或者大家只是使用第三方树视图控件?

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?

你是正确的,因为没有数据绑定。原因是TreeViews是分层数据结构。也就是说,不是一个直接的列表。因此,数据绑定选项无效表示列表结构。

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.)

这是一个不错的MSDN文章,在绑定分层数据

Here's a decent MSDN article on Binding Hierarchical Data.