最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用combobox C#绑定树视图

SEO心得admin63浏览0评论
本文介绍了使用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(); }

发布评论

评论列表(0)

  1. 暂无评论