2
Answers

saving data in datatable using recursive function

In the below function I have a DataTable which resets during recursion of the function. How can I solve this problem?
I have to create table once and add rows repeatedly in each repeat of the function.
 
Please help! 
 
 
private DataTable GetSelectedTreeNodes(TreeNode parentTreeNode)
{
   DataTable tvp = new DataTable();
   tvp.Columns.Add(new DataColumn("Suburb"));
   if (parentTreeNode.Checked)
   {
      ListBox1.Items.Add(parentTreeNode.Text);
      tvp.Rows.Add(parentTreeNode.Text);
      tvp.Rows.Add(parentTreeNode.Text);
   }
   if (parentTreeNode.ChildNodes.Count > 0)
   {
   foreach (TreeNode childTreeNode in parentTreeNode.ChildNodes)
   {
      GetSelectedTreeNodes(childTreeNode);
   }
}
return tvp;
}
Answers (2)