Home DevExpress Tips How to add new node to the dexexpress treelist
Author:

 How to  add a node to the existing DevExpress treelist dynamically?

 

You can do it using this below code. You will need to create a new object array, the number of the arrays will depends how many column is in your datasource.

TreeListNode newNode = tlFuncLoc.AppendNode(new object[] { newEntityID, txtNumber.Text, txtName.Text }, parentNode);

newNode.SetValue(1, parentNode.GetValue(1).ToString() + "-" + txtNumber.Text);

  

SAMPLE CODE:

 

int newEntityID = -1;

 

//Insert a record into the database

Database db = DatabaseFactory.CreateDatabase();

 

TreeListNode parentNode = tlFuncLoc.Selection[0];

int entityID = int.Parse(parentNode.GetValue(0).ToString());

 

string message = String.Empty;

 

DbCommand dbCommand = db.GetStoredProcCommand("dbo.prEntityInsert");

db.AddInParameter(dbCommand, "EntityNumber", DbType.String, txtNumber.Text);

db.AddInParameter(dbCommand, "EntityName", DbType.String, txtName.Text);

db.AddInParameter(dbCommand, "ParentEntityID", DbType.Int32, entityID);

db.AddOutParameter(dbCommand, "newEntityID", DbType.Int32, newEntityID);

 

db.ExecuteNonQuery(dbCommand);

newEntityID = int.Parse(db.GetParameterValue(dbCommand, "newEntityID").ToString());

//Update tree node

 

TreeListNode newNode = tlFuncLoc.AppendNode(new object[] { newEntityID, txtNumber.Text, txtName.Text }, parentNode);

newNode.SetValue(1, parentNode.GetValue(1).ToString() + "-" + txtNumber.Text);



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"