DEVEXPRESS-----TREELIST 的 增加、删除节点

转载 2006年05月30日 15:49:00

  注意采用了两个treeListColumn,一个用来展示名称,一个用来展示编码.这样的好处在于作品名维护的时候,可以调用编码,而不需要重新匹配对比了.下面是完整的代码.

using System;
using System.Drawing;
using System. Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsApplication1
{
    
/**//// <summary>
    
/// typemanage 的摘要说明。
    
/// </summary>
    public class typemanage : System.Windows.Forms.Form
    
{
        
private DevExpress.XtraEditors.TextEdit textEdit1;
        
private DevExpress.XtraTreeList.TreeList treeList1;
        
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn1;
        
private DevExpress.XtraEditors.Repository.RepositoryItemTextEdit repositoryItemTextEdit1;
        
private DevExpress.XtraEditors.SimpleButton simpleButton1;
        
private DevExpress.XtraEditors.SimpleButton simpleButton2;
        
private DevExpress.XtraEditors.SimpleButton simpleButton3;
        
private System.Windows.Forms.Label label1;
        
int nodeid=0;
        DevExpress.XtraTreeList.Nodes.TreeListNode deletenode;
        
private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn2;
        
private DevExpress.XtraEditors.Repository.RepositoryItemTextEdit repositoryItemTextEdit2;
        
private System.Windows.Forms.Label label2;
        
private DevExpress.XtraEditors.TextEdit textEdit2;
        
/**//// <summary>
        
/// 必需的设计器变量。
        
/// </summary>
        private System.ComponentModel.Container components = null;

        
public typemanage()
        
{
            
//
            // Windows 
窗体设计器支持所必需的
            //
            InitializeComponent();

            
//
            // TODO: 
 InitializeComponent 调用后添加任何构造函数代码
            //
        }

        
/**//// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>
        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if(components != null)
                
{
                    components.Dispose();
                }
            }
            
base.Dispose( disposing );
        }

        
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
        
/**//// <summary>
        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
        
/// 此方法的内容。
        
/// </summary>
        private void InitializeComponent()
        
{
            
this.textEdit1 = new DevExpress.XtraEditors.TextEdit();
            
this.treeList1 = new DevExpress.XtraTreeList.TreeList();
            
this.treeListColumn1 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
            
this.repositoryItemTextEdit1 = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
            
this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton();
            
this.simpleButton2 = new DevExpress.XtraEditors.SimpleButton();
            
this.simpleButton3 = new DevExpress.XtraEditors.SimpleButton();
            
this.label1 = new System.Windows.Forms.Label();
            
this.treeListColumn2 = new DevExpress.XtraTreeList.Columns.TreeListColumn();
            
this.repositoryItemTextEdit2 = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
            
this.label2 = new System.Windows.Forms.Label();
            
this.textEdit2 = new DevExpress.XtraEditors.TextEdit();
            ((System.ComponentModel.ISupportInitialize)(
this.textEdit1.Properties)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this.treeList1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this.repositoryItemTextEdit1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this.repositoryItemTextEdit2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(
this.textEdit2.Properties)).BeginInit();
            
this.SuspendLayout();
            
// 
            // textEdit1
            // 
            this.textEdit1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            
this.textEdit1.EditValue = "新增1";
            
this.textEdit1.Location = new System.Drawing.Point(88, 248);
            
this.textEdit1.Name = "textEdit1";
            
this.textEdit1.Size = new System.Drawing.Size(128, 21);
            
this.textEdit1.TabIndex = 12;
            
// 
            // treeList1
            // 
            this.treeList1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Right)));
            
this.treeList1.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[]  {
                                                                                                     
this.treeListColumn1,
                                                                                                     
this.treeListColumn2});
            
this.treeList1.Location = new System.Drawing.Point(224, 16);
            
this.treeList1.Name = "treeList1";
            
this.treeList1.BeginUnboundLoad();
            
this.treeList1.AppendNode(new object[]  {
                                                       "
型材",
                                                       "01"}, -1);
            
this.treeList1.AppendNode(new object[]  {
                                                       "
门窗五金",
                                                       "02"}, -1);
            
this.treeList1.AppendNode(new object[]  {
                                                       "
辅料",
                                                       "03"}, -1);
            
this.treeList1.AppendNode(new object[]  {
                                                       "
中空玻璃用料",
                                                       "04"}, -1);
            
this.treeList1.EndUnboundLoad();
            
this.treeList1.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[]  {
                                                                                                               
this.repositoryItemTextEdit1,
                                                                                                               
this.repositoryItemTextEdit2});
            
this.treeList1.Size = new System.Drawing.Size(264, 264);
            
this.treeList1.Styles.AddReplace("Preview", new DevExpress.Utils.ViewStyle("Preview", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truetruefalse, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255))), System.Drawing.Color.FromArgb(((System.Byte)(10)), ((System.Byte)(36)), ((System.Byte)(106)))));
            
this.treeList1.Styles.AddReplace("FooterPanel", new DevExpress.Utils.ViewStyle("FooterPanel", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Far, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("GroupButton", new DevExpress.Utils.ViewStyle("GroupButton", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(252)), ((System.Byte)(248)), ((System.Byte)(240))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("EvenRow", new DevExpress.Utils.ViewStyle("EvenRow", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("TreeLine", new DevExpress.Utils.ViewStyle("TreeLine", "TreeList", new System.Drawing.Font("Microsoft Sans Serif", 8F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255))), System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128)))));
            
this.treeList1.Styles.AddReplace("PressedColumn", new DevExpress.Utils.ViewStyle("PressedColumn", "TreeList", new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold), "HeaderPanel", ((DevExpress.Utils.StyleOptions)(((DevExpress.Utils.StyleOptions.StyleEnabled | DevExpress.Utils.StyleOptions.UseBackColor) 
                | DevExpress.Utils.StyleOptions.UseForeColor))), 
truefalsefalse, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(10)), ((System.Byte)(36)), ((System.Byte)(106))), System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)))));
            
this.treeList1.Styles.AddReplace("HideSelectionRow", new DevExpress.Utils.ViewStyle("HideSelectionRow", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", ((DevExpress.Utils.StyleOptions)((((((DevExpress.Utils.StyleOptions.StyleEnabled | DevExpress.Utils.StyleOptions.UseBackColor) 
                | DevExpress.Utils.StyleOptions.UseDrawFocusRect) 
                | DevExpress.Utils.StyleOptions.UseFont) 
                | DevExpress.Utils.StyleOptions.UseForeColor) 
                | DevExpress.Utils.StyleOptions.UseImage))), 
truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128))), System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200)))));
            
this.treeList1.Styles.AddReplace("GroupFooter", new DevExpress.Utils.ViewStyle("GroupFooter", "TreeList", new System.Drawing.Font("Tahoma", 8F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Far, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(218)), ((System.Byte)(210))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("HorzLine", new DevExpress.Utils.ViewStyle("HorzLine", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200))), System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128)))));
            
this.treeList1.Styles.AddReplace("HeaderPanel", new DevExpress.Utils.ViewStyle("HeaderPanel", "TreeList", new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("Empty", new DevExpress.Utils.ViewStyle("Empty", "TreeList", new System.Drawing.Font("Microsoft Sans Serif", 8F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(232)), ((System.Byte)(228)), ((System.Byte)(220))), System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)))));
            
this.treeList1.Styles.AddReplace("VertLine", new DevExpress.Utils.ViewStyle("VertLine", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(212)), ((System.Byte)(208)), ((System.Byte)(200))), System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128)))));
            
this.treeList1.Styles.AddReplace("FocusedCell", new DevExpress.Utils.ViewStyle("FocusedCell", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", ((DevExpress.Utils.StyleOptions)((((((DevExpress.Utils.StyleOptions.StyleEnabled | DevExpress.Utils.StyleOptions.UseBackColor) 
                | DevExpress.Utils.StyleOptions.UseDrawFocusRect) 
                | DevExpress.Utils.StyleOptions.UseFont) 
                | DevExpress.Utils.StyleOptions.UseForeColor) 
                | DevExpress.Utils.StyleOptions.UseImage))), 
truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(225))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("OddRow", new DevExpress.Utils.ViewStyle("OddRow", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.Styles.AddReplace("SelectedRow", new DevExpress.Utils.ViewStyle("SelectedRow", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", ((DevExpress.Utils.StyleOptions)((((((DevExpress.Utils.StyleOptions.StyleEnabled | DevExpress.Utils.StyleOptions.UseBackColor) 
                | DevExpress.Utils.StyleOptions.UseDrawFocusRect) 
                | DevExpress.Utils.StyleOptions.UseFont) 
                | DevExpress.Utils.StyleOptions.UseForeColor) 
                | DevExpress.Utils.StyleOptions.UseImage))), 
truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(20)), ((System.Byte)(46)), ((System.Byte)(116))), System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)))));
            
this.treeList1.Styles.AddReplace("FocusedRow", new DevExpress.Utils.ViewStyle("FocusedRow", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", ((DevExpress.Utils.StyleOptions)((((((DevExpress.Utils.StyleOptions.StyleEnabled | DevExpress.Utils.StyleOptions.UseBackColor) 
                | DevExpress.Utils.StyleOptions.UseDrawFocusRect) 
                | DevExpress.Utils.StyleOptions.UseFont) 
                | DevExpress.Utils.StyleOptions.UseForeColor) 
                | DevExpress.Utils.StyleOptions.UseImage))), 
truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(10)), ((System.Byte)(36)), ((System.Byte)(106))), System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)))));
            
this.treeList1.Styles.AddReplace("Row", new DevExpress.Utils.ViewStyle("Row", "TreeList", new System.Drawing.Font("Tahoma", 10F), "", DevExpress.Utils.StyleOptions.StyleEnabled, truefalsefalse, DevExpress.Utils.HorzAlignment.Default, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255))), System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)))));
            
this.treeList1.TabIndex = 23;
            
this.treeList1.Text = "类型维护";
            
this.treeList1.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(this.treeList1_FocusedNodeChanged);
            
this.treeList1.AfterFocusNode += new DevExpress.XtraTreeList.NodeEventHandler(this.treeList1_AfterFocusNode);
            
// 
            // treeListColumn1
            // 
            this.treeListColumn1.Caption = "类型维护----绿城铝业";
            
this.treeListColumn1.ColumnEdit = this.repositoryItemTextEdit1;
            
this.treeListColumn1.FieldName = "类型维护----绿城铝业";
            
this.treeListColumn1.Name = "treeListColumn1";
            
this.treeListColumn1.VisibleIndex = 0;
            
// 
            // repositoryItemTextEdit1
            // 
            this.repositoryItemTextEdit1.AutoHeight = false;
            
this.repositoryItemTextEdit1.Name = "repositoryItemTextEdit1";
            
// 
            // simpleButton1
            // 
            this.simpleButton1.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Office2003;
            
this.simpleButton1.Location = new System.Drawing.Point(40, 24);
            
this.simpleButton1.Name = "simpleButton1";
            
this.simpleButton1.TabIndex = 27;
            
this.simpleButton1.Text = " 新增根";
            
this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
            
// 
            // simpleButton2
            // 
            this.simpleButton2.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Office2003;
            
this.simpleButton2.Location = new System.Drawing.Point(40, 128);
            
this.simpleButton2.Name = "simpleButton2";
            
this.simpleButton2.TabIndex = 28;
            
this.simpleButton2.Text = "删除节点";
            
this.simpleButton2.Click += new System.EventHandler(this.simpleButton2_Click);
            
// 
            // simpleButton3
            // 
            this.simpleButton3.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.Office2003;
            
this.simpleButton3.Location = new System.Drawing.Point(40, 80);
            
this.simpleButton3.Name = "simpleButton3";
            
this.simpleButton3.TabIndex = 30;
            
this.simpleButton3.Text = " 新增子极";
            
this.simpleButton3.Click += new System.EventHandler(this.simpleButton3_Click);
            
// 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            
this.label1.Location = new System.Drawing.Point(8, 256);
            
this.label1.Name = "label1";
            
this.label1.Size = new System.Drawing.Size(80, 16);
            
this.label1.TabIndex = 31;
            
this.label1.Text = "新增节点名称";
            
// 
            // treeListColumn2
            // 
            this.treeListColumn2.Caption = "对应编码";
            
this.treeListColumn2.ColumnEdit = this.repositoryItemTextEdit2;
            
this.treeListColumn2.FieldName = "treeListColumn2";
            
this.treeListColumn2.Name = "treeListColumn2";
            
this.treeListColumn2.VisibleIndex = 1;
            
// 
            // repositoryItemTextEdit2
            // 
            this.repositoryItemTextEdit2.AutoHeight = false;
            
this.repositoryItemTextEdit2.Name = "repositoryItemTextEdit2";
            
// 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            
this.label2.Location = new System.Drawing.Point(8, 288);
            
this.label2.Name = "label2";
            
this.label2.Size = new System.Drawing.Size(80, 16);
            
this.label2.TabIndex = 33;
            
this.label2.Text = "节点对应代码";
            
// 
            // textEdit2
            // 
            this.textEdit2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            
this.textEdit2.EditValue = "05";
            
this.textEdit2.Location = new System.Drawing.Point(88, 280);
            
this.textEdit2.Name = "textEdit2";
            
this.textEdit2.Size = new System.Drawing.Size(128, 21);
            
this.textEdit2.TabIndex = 32;
            
// 
            // typemanage
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            
this.ClientSize = new System.Drawing.Size(496, 333);
            
this.Controls.Add(this.label2);
            
this.Controls.Add(this.textEdit2);
            
this.Controls.Add(this.label1);
            
this.Controls.Add(this.simpleButton3);
            
this.Controls.Add(this.simpleButton2);
            
this.Controls.Add(this.simpleButton1);
            
this.Controls.Add(this.treeList1);
            
this.Controls.Add(this.textEdit1);
            
this.Name = "typemanage";
            
this.Text = "类型管理";
            ((System.ComponentModel.ISupportInitialize)(
this.textEdit1.Properties)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this.treeList1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this.repositoryItemTextEdit1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this.repositoryItemTextEdit2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(
this.textEdit2.Properties)).EndInit();
            
this.ResumeLayout(false);

        }
        
#endregion

        
private void simpleButton1_Click(object sender, System.EventArgs e)
        
{
            
if(textEdit1.Text.Trim()==""||textEdit2.Text.Trim()=="")
            
{
                MessageBox.Show("
请输入对应名称及编码!","错误",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                
return;
            }
            
this.treeList1.AppendNode(new object[]  {this.textEdit1.Text,textEdit2.Text},-1);

        
//            newnode.
        //            this.treeList1.Nodes[0].Nodes.Add(newnode);
       }

        
private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        
{
            MessageBox.Show(e.Node.Level.ToString());
            MessageBox.Show(e.Node.Id.ToString());
            MessageBox.Show(e.Node.GetDisplayText(0));
        }

        
private void treeList1_AfterFocusNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
        
{
            nodeid=e.Node.Id;
            deletenode=e.Node;
        }

        
private void simpleButton3_Click(object sender, System.EventArgs e)
        
{
            
if(textEdit1.Text.Trim()==""||textEdit2.Text.Trim()=="")
            
{
                MessageBox.Show("
请输入对应名称及编码!","错误",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                
return;
            }
            
this.treeList1.AppendNode(new object[]  {this.textEdit1.Text,textEdit2.Text},nodeid);
        }

        
private void simpleButton2_Click(object sender, System.EventArgs e)
        
{
//            MessageBox.Show(nodeid.ToString());
            this.treeList1.DeleteNode(deletenode);
        }
    }
}

相关文章推荐

DEV系列--treeList用法

从数据库读取数据显示到treeList中 效果图: 数据库表的设计图: 源代码: using System; using System.Collections.Generic; using S...

DevExpress控件XtraTreeList的使用心得

数据展示 数据源绑定 需要设置KeyFieldName和ParentFieldName后绑定数据 treeList1.DataSource = dataTable1; 且KeyFieldNam...

[DevExpress]TreeList显示[+] [-] 线条样式

预设显示下拉三角形样式,需要设置TreeList的两个皮肤属性:C# Code:tree.LookAndFeel.UseDefaultLookAndFeel = false;tree.LookAndF...

[Dev]DevExpress之treelist右键菜单实现

添加BarManager和popupMenu组件:设置popupMenu组件的Manager属性:右键点击popupMenu主键,点击Customize选项添加菜单代码:using System; u...

Dev Treelist使用经验(1)

Dev Treelist使用经验(1) 最近项目使用很频繁,主要是treelist控件的使用 当前输入列进行判断 触发的事件是treeList1_CellValueChanged 其中需要判断...

第三方控件DEV中的TreeList如何显示树形结构

private void reflishcategory()               //刷新treelist使用 {             TreeListNode node = null...

DEV系列--treeList用法(2)

不从数据库读数据,创建一个Datatable绑定到treeList上,效果图: 源代码: using System; using System.Collections.Generic; using...

DEV TreeList的节点设置

存个档,以后直接用了。 基本做到:1.选中父节点,子节点根据父节点选中状态调整自身状态。2选中子节点,父节点根据子节点的兄弟节点的状态调整自身状态。 private void treeList1...

Dev TreeList树控件使用

Winform 快速初始化Dev TreeList树控件的数据 使用Id,ParentId数据结构即可初始化TreeList,如下图: 图中TreeList控件命名tlCategory。 产...

dev treelist 常用用法小结

要求如下: 1:选择父节点后,子节点全部打钩; 2:选择子节点而不选择父节点,则从当前节点的父节点一直到根节点check框都是半选状态。 3:当子节点均未勾选时,设置父节点状态为:未选中状态 具体实现...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:DEVEXPRESS-----TREELIST 的 增加、删除节点
举报原因:
原因补充:

(最多只允许输入30个字)