我有一个简单的代码,用于创建带有添加、删除和编辑按钮的树结构。我想通过文本框 (textBox1) 和按钮按下 (button4) 从添加的节点中搜索特定节点,但我似乎无法使其工作。有什么建议么?using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form{ public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { TreeNode node = new TreeNode(textBox1.Text); try { treeView1.SelectedNode.Nodes.Add(node); } catch (Exception) { treeView1.Nodes.Add(node); } } private void Button2_Click(object sender, EventArgs e) { treeView1.SelectedNode.Text = textBox1.Text; } private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) { textBox1.Text = treeView1.SelectedNode.Text; } private void Button3_Click(object sender, EventArgs e) { treeView1.SelectedNode.Remove(); } private void Button4_Click(object sender, EventArgs e) { }}}
1 回答
30秒到达战场
TA贡献1828条经验 获得超6个赞
像这样使用 linq 查询:
TreeNode[] treeNodes = treeView1.Nodes.Cast<TreeNode>() .Where(r => r.Text == textBox1.Text).ToArray();
- 1 回答
- 0 关注
- 54 浏览
添加回答
举报
0/150
提交
取消