C#上移,下移TreeView中的树节点顺序
C#中,通过单击上移,下移按钮移动树节点中的节点顺序的实现方法:
- public Form1()
- {
- InitializeComponent();
- }
- TreeNode preNode, nextNode, currentNode;
- int g_tag;
- string g_text;
- private void Form1_Load(object sender, EventArgs e)
- {
- TreeNode tn = new TreeNode();
- tn.Nodes.Add("北京");
- tn.Tag = 1;
- tn.Nodes.Add("湖北");
- tn.Tag = 2;
- tn.Nodes.Add("上海");
- tn.Tag = 3;
- tn.Nodes.Add("天津");
- tn.Tag = 4;
- treeView1.Nodes.Add(tn);
- }
- //上移
- private void button2_Click(object sender, EventArgs e)
- {
- currentNode = treeView1.SelectedNode;
- if (currentNode == null)
- {
- return;
- }
- else
- {
- preNode = currentNode.PrevNode;
- if (preNode == null)
- {
- return;
- }
- else
- {
- g_text= preNode.Text;
- g_tag=Convert.ToInt32( preNode.Tag);
- preNode.Tag= currentNode.Tag;
- preNode.Text = currentNode.Text;
- currentNode.Tag = g_tag;
- currentNode.Text = g_text;
- }
- }
- }
- //下移
- private void button3_Click(object sender, EventArgs e)
- {
- currentNode = treeView1.SelectedNode;
- if (currentNode == null)
- {
- return;
- }
- else
- {
- preNode = currentNode.NextNode;
- if (preNode == null)
- {
- return;
- }
- else
- {
- g_text = preNode.Text;
- g_tag = Convert.ToInt32(preNode.Tag);
- preNode.Tag = currentNode.Tag;
- preNode.Text = currentNode.Text;
- currentNode.Tag = g_tag;
- currentNode.Text = g_text;
- }
- }
- }
在窗体中拖1个treeView控件和两个button,按照上面思路实现就可以了。
C#上移,下移TreeView中的树节点顺序的更多相关文章
- AppBox中main树节点单击事件JS(还有叶子的节点的页面链接)
AppBox中main.aspx.csif (menu.IsTreeLeaf) { node.Leaf = true; ...
- TreeView中右击直接获取节点的方法
在TreeView中无法直接右击得到一个节点,因为当你选中其中一个右击时(不能是第一个)他会默认跳到第一个. 有时我们要想直接右击得到选中的节点,又时我们又想选中直接右击跳出一个快捷菜单怎么办了! 在 ...
- 修复jquery.treeview的增加子节点的方法的bug
1.修复理由 在一个android项目中用到了treeview控件(本来自己通过android的原生api实现了一个http://www.cnblogs.com/Mr-Nobody/p/3527688 ...
- TreeView 树节点的处理
TreeView 树节点的处理 using System; using System.Collections.Generic; using System.ComponentModel; using S ...
- 问题-在TreeView使用时,发现选中的树节点会闪烁或消失
问题:在工程中选中一个树节点,鼠标焦点在树上,做某种操作时发现选中的点会消失?原因:如果只是BeginUpdate后,没有调用EndUpdate,树会全空.应该是BeginUpdate方法会刷新树,但 ...
- table中实现数据上移下移效果
html 由于vue+Element项目中的table,没有开放的上移下移的api,但是能对数据操作,故思路为数组中的一条数据,再重新添加一条数据,办法有点笨,但是好歹也是实现了,望有好的办法的,请留 ...
- ext 树节点操作
ext 树节点操作 tree :树 node:节点 1.全部展开 tree.expandAll(); 2.全部收缩 tree.collapseAll(); 3.得到父节点 node.parent ...
- WPF:使用Json.NET在TreeView中树形显示JSON数据
原文 WPF:使用Json.NET在TreeView中树形显示JSON数据 据 读者可以参考这个开源的可以树形显示XML和JSON的工具: Mgen Object 603:XML/JSON树形显示小工 ...
- 向treeview中加载数据
1.获取树节点的值,用事件AfterSelect加载(id值的获取,用name来获取) 2.双击treeview控件得到 private void treeView1_AfterSelect(obje ...
随机推荐
- node(koa)微信公众号接口认证
使用微信测试号, 花生壳内网穿透 需要注意 token 两边都是自定义, 需要保持一致, const Koa = require('koa') const sha1 = require('sha1') ...
- 关闭掉eclipse启动的自动更新功能(提高打开eclipse的速度)
- ABP初始化
默认认为你手中已经有abp-zero项目,当前4.6.0 angularJS切换到jquery 运行项目,初始化是跳转到~/App/common/views/layout/layout.cshtml, ...
- getdlgitemtext
获取控件内信息 set 设置控件内信息 oninitdialog初始化控件时的操作
- H5及微信中唤起app的解决方案
今天我们就来说说这个callapp-lib 我的接到的需求大概是这样的 如果检测到不是在app里面用webview打开的页面就会显示上面的立即打开按钮, 点击的话会判断是否在微信中, 如果在微信中打开 ...
- BZOJ 2850: 巧克力王国 KDtree + 估价函数
Code: #include<bits/stdc++.h> #define maxn 100000 #define inf 1000000008 #define mid ((l+r)> ...
- hdu 2084 数塔(简单dp)
题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...
- oralce 创建表空间 和 查询进程
-- Create the user create user lesdba identified by les_321 default tablespace USERS temporary table ...
- php 漏洞分析
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串.
- vue轮播插件vue-awesome-swiper
https://surmon-china.github.io/vue-awesome-swiper/ 第一步安装 npm install vue-awesome-swiper --save 第二部在m ...