使用combobox C#绑定树视图

编程入门 行业动态 更新时间:2024-10-07 04:35:13
本文介绍了使用combobox C#绑定树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有Treeview与 节点 -Node1 -Node1Child -Node2 -Node2Child 和带数据的ComboBox Combo1 Combo2 如果Node1Child单击然后在ComboBox中显示Node1Child如何使其工作并且可以更改为Combo2值? 我曾尝试过: i搜索无处不在,无法找到C#

i have Treeview with Node -Node1 -Node1Child -Node2 -Node2Child and ComboBox with data Combo1 Combo2 how to make it work if Node1Child Clicked then in ComboBox Show Node1Child and can be changed woth Combo2 value? What I have tried: i search everywhere and cannot find solution for C#

推荐答案

的解决方案 AfterSelect()事件仅触发新选择,如果已选中则不会触发。您可能希望捕获TreeView的Click事件。 The AfterSelect() event only fires for new selections and won't fire if already selected. You may want to capture the TreeView's Click event instead. private void treeView1_Click(object sender, EventArgs e) { TreeViewHitTestInfo info = treeView1.HitTest(treeView1.PointToClient(Cursor.Position)); if (info != null) MessageBox.Show(info.Node.Text); }

编辑: 以下是我认为你试图做的事情:

Here is what I think that you are attempting to do:

private void treeView1_Click(object sender, EventArgs e) { TreeViewHitTestInfo info = treeView1.HitTest(treeView1.PointToClient(Cursor.Position)); if (info != null) { comboBox1.DisplayMember = "Text"; comboBox1.DataSource = info.Node.Nodes; } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { var node = comboBox1.SelectedItem as TreeNode; if (node == null) return; treeView1.SelectedNode = node; treeView1.Focus(); }

更多推荐

使用combobox C#绑定树视图

本文发布于:2023-11-30 06:41:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   绑定   combobox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!