| |

VerySource

 Forgot password?
 Register
Search
View: 709|Reply: 7

How to delete selected nodes in TreeView

[Copy link]

1

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 23:50:01
| Show all posts |Read mode
protected void btnDelSub_Click (object sender, EventArgs e)
    {
        string strParentID = this.tvwType.SelectedNode.Value.ToString (). Trim ();
        string strParent = this.tvwType.SelectedNode.Value.ToString (). Trim () + ",";
        this.tvwType.SelectedNode.ChildNodes.Clear ();
    }

In this way, only the nodes below the selected node can be deleted, but the node itself cannot be deleted.
How to delete the selected node in TreeView?
Reply

Use magic Report

1

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-7 01:15:01
| Show all posts
Top
Reply

Use magic Report

1

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-7 05:18:01
| Show all posts
this.tvwType.SelectedNode.Parent.RemoveAt (this.tvwType.SelectedNode);
Reply

Use magic Report

1

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-7 07:21:01
| Show all posts
Big brother upstairs,

 System.Web.UI.WebControls.TreeNode does not contain the definition of RemoveAt,

Do you want to add USING?
Reply

Use magic Report

1

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-7 07:48:01
| Show all posts
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

Yes. NET2005
Reply

Use magic Report

1

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-7 09:06:01
| Show all posts
sorry

this.tvwType.RemoveAt (this.tvwType.SelectedNode);
Reply

Use magic Report

1

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-7 09:12:01
| Show all posts
Haha, it still doesn't work
This line tvwType.SelectedNode.Parent.ChildNodes.Remove (this.tvwType.SelectedNode);

Thank you anyway
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-11 06:45:01
| Show all posts
Just do n’t do that.
 treeView1.Nodes.Remove (treeView1.SelectedNode);
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list