• C#上移,下移TreeView中的树节点顺序


     

    C#上移,下移TreeView中的树节点顺序

     1494人阅读 评论(2) 收藏 举报

         C#中,通过单击上移,下移按钮移动树节点中的节点顺序的实现方法:

    [c-sharp] view plaincopy
    1. public Form1()  
    2.       {  
    3.           InitializeComponent();  
    4.       }  
    5.       TreeNode preNode, nextNode, currentNode;  
    6.       int g_tag;  
    7.       string g_text;  
    8.       private void Form1_Load(object sender, EventArgs e)  
    9.       {  
    10.           TreeNode tn = new TreeNode();  
    11.           tn.Nodes.Add("北京");  
    12.           tn.Tag = 1;  
    13.           tn.Nodes.Add("湖北");  
    14.           tn.Tag = 2;  
    15.           tn.Nodes.Add("上海");  
    16.           tn.Tag = 3;  
    17.           tn.Nodes.Add("天津");  
    18.           tn.Tag = 4;  
    19.           treeView1.Nodes.Add(tn);  
    20.   
    21.       }  
    22.       //上移  
    23.       private void button2_Click(object sender, EventArgs e)  
    24.       {  
    25.           currentNode = treeView1.SelectedNode;  
    26.           if (currentNode == null)  
    27.           {  
    28.               return;  
    29.           }  
    30.           else  
    31.           {  
    32.               
    33.               preNode = currentNode.PrevNode;  
    34.               if (preNode == null)  
    35.               {  
    36.                   return;  
    37.               }  
    38.               else  
    39.               {  
    40.                  g_text= preNode.Text;  
    41.                 g_tag=Convert.ToInt32( preNode.Tag);  
    42.                preNode.Tag= currentNode.Tag;  
    43.                preNode.Text = currentNode.Text;  
    44.                currentNode.Tag = g_tag;  
    45.                currentNode.Text = g_text;  
    46.               }  
    47.           }  
    48.           
    49.             
    50.       }  
    51.        //下移  
    52.       private void button3_Click(object sender, EventArgs e)  
    53.       {  
    54.   
    55.           currentNode = treeView1.SelectedNode;  
    56.           if (currentNode == null)  
    57.           {  
    58.               return;  
    59.           }  
    60.           else  
    61.           {  
    62.   
    63.               preNode = currentNode.NextNode;  
    64.               if (preNode == null)  
    65.               {  
    66.                   return;  
    67.               }  
    68.               else  
    69.               {  
    70.                   g_text = preNode.Text;  
    71.                   g_tag = Convert.ToInt32(preNode.Tag);  
    72.                   preNode.Tag = currentNode.Tag;  
    73.                   preNode.Text = currentNode.Text;  
    74.                   currentNode.Tag = g_tag;  
    75.                   currentNode.Text = g_text;  
    76.               }  
    77.           }  
    78.       }  

    在窗体中拖1个treeView控件和两个button,按照上面思路实现就可以了。

  • 相关阅读:
    MySQL ON DUPLICATE KEY UPDATE 语法
    MySQl 截取函数 left(),right(),substring(),substring_index() 的用法
    MySQL timestampdiff 和 timestampadd 的用法
    MySQL replace 和 replace into 的用法
    MySQL exists 和 not exists 的用法
    MySQL concat、concat_ws 和 group_concat 的用法
    Python数据类型及其方法详解
    《Python编程从入门到实践》_第八章_函数
    《Python编程从入门到实践》_第七章_用户输入和whlie循环
    编码的秘密(python版)
  • 原文地址:https://www.cnblogs.com/meimao5211/p/3346316.html
Copyright © 2020-2023  润新知