private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { var nodes = treeView1.Nodes; comboBox1.DisplayMember = "Text"; comboBox1.DataSource = nodes; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { var node = comboBox1.SelectedItem as TreeNode; if (node == null) return; treeView1.SelectedNode = node; }
// // treeView1 // this.treeView1.Location = new System.Drawing.Point(121, 24); this.treeView1.Name = "treeView1"; treeNode1.Name = "Node2"; treeNode1.Text = "Node2"; treeNode2.Name = "Node1"; treeNode2.Text = "Node1"; treeNode3.Name = "Node1"; treeNode3.Text = "Node1"; treeNode4.Name = "Node0"; treeNode4.Text = "List of Node"; this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] { treeNode4}); this.treeView1.Size = new System.Drawing.Size(147, 215); this.treeView1.TabIndex = 2; this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Items.AddRange(new object[] { "list_c1", "list_c2", "list_c3"}); this.comboBox1.Location = new System.Drawing.Point(5, 123); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(110, 21); this.comboBox1.TabIndex = 3; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);