Prakash Malakar

Prakash Malakar

  • NA
  • 13
  • 4.8k

saving data in datatable using recursive function

Apr 23 2015 1:21 AM
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)