亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何通過按下按鈕時輸入的文本搜索此樹視圖中的特定節點?

如何通過按下按鈕時輸入的文本搜索此樹視圖中的特定節點?

C#
蠱毒傳說 2022-12-31 10:55:11
我有一個簡單的代碼,用于創建帶有添加、刪除和編輯按鈕的樹結構。我想通過文本框 (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();


查看完整回答
反對 回復 2022-12-31
  • 1 回答
  • 0 關注
  • 71 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號