使用树视图数据和同步选择填充组合框 [英] Populate a Combo Box with a Tree View data and sync selection

查看:196
本文介绍了使用树视图数据和同步选择填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Stackoverflow Contributor,



我有一个组合框CmboExpenseType,暂时没有数据。





我也有一个树状图TVProperties包含以下数据。





我想从这个树视图的父节点到CmboExpenseType。



因此,当用户点击组合框时,他们将看到父节点收入,娱乐,运输和其他,然后我可以编程子节点到另一个组合框。



不是 试图获取一个组合框到我的树视图。 / p>

我此时只尝试过这段代码。但它没有效果。

  CmboExpenseType.Items.Add(TVProperties); 

是否值得我将节点移动到列表或字典?



我有一些关于在获得所有父节点之后可能的方法的想法,像一个可能的foreach循环。我只是坚持将树视图中的数据添加到我的组合框中。



任何帮助将是太棒了。如果需要更多信息,请不要犹豫告诉我。

解决方案

如果你想从现有的TreeView ,您可以执行以下操作:

  var list = TVProperties.Nodes 
.Cast< TreeNode>()
。Select(x => x.Text)
.ToList();

CmboExpenseType.DataSource = list;

不知道如何填充 TreeView 在第一个地方,很容易只用第一级节点数据填充 ComboBox


Hello Stackoverflow Contributors,

I have a Combo Box "CmboExpenseType" with no data in at the moment.

I also have a Tree View "TVProperties" with the following data.

I'd like to get the Parent Nodes from this tree view into the "CmboExpenseType".

So when the user clicks on the Combo Box they will see the parent nodes "Income, Entertainment, Transportation & Others" and then I can program the Child Nodes to go into another Combo Box.

I'm not trying to get a Combo Box into my Tree View.

I have only tried this code at this time. But it worked to no avail.

CmboExpenseType.Items.Add(TVProperties);

Would it be worth me moving the nodes into a list or dictionary?

I have some ideas on possible ways after of getting all Parent Nodes in, like a possible foreach loop. I'm just stuck on adding the data from the Tree View into my Combo Box.

Any help would be fantastic. If more information is need please don't hesitate to tell me.

解决方案

If you want to take the node text from existing TreeView, you can do the following

var list = TVProperties.Nodes
                       .Cast<TreeNode>()
                       .Select(x=> x.Text)
                       .ToList();

CmboExpenseType.DataSource = list;

Not sure about how you populate the TreeView in first place, It will be easy to populate the ComboBox at the same time with only first level node data.

这篇关于使用树视图数据和同步选择填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆