Jacob_pgr
Jacob_pgr

Reputation: 99

how to add a row in existing datatable

In a vb.net Windows Application, I have a datatable wich is not from a database. I want to add a new row, but when I add a new row only the new row is in the datatable, not the existing data.

dim dt as datatable treelist.datasource=dt this is existing item here in any event i want to add the new row in the datatable so that new node is added to the treelist

thanks for your help....

Upvotes: 0

Views: 21876

Answers (1)

David Hague
David Hague

Reputation: 142

You should be able to declare a new row and add it to the DataTable as such:

'Create the new row
Dim newRow as DataRow = myTable.NewRow

'Add some data to it
newRow("columnName1") = data1
newRow("columnName2") = data2

'Add it to the table
myTable.Rows.Add(newRow)

'Bind the table
treeList.DataSource = dt
treeList.DataBind

That should work, just make sure you add the row to the DataTable before you bind it to the TreeView object.

Upvotes: 2

Related Questions