Export treeview nodes with identation

  • Thread starter Thread starter HansvB69
  • Start date Start date
H

HansvB69

Guest
Hi,

Is it possible to export the treeview node names to a text file with the proper identation like this:

Node 1

child 1

child 2

child 3

child 3.1

child 3.1

child3.1.1

Node 2

child 1

child 2



I have this so far:

private void ExportAllNodeNamesToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Tekst bestand|*.txt";
saveFileDialog1.Title = "Opslaan alle map en query namen.";
saveFileDialog1.ShowDialog();

// If the file name is not an empty string open it for saving.
if (saveFileDialog1.FileName != "")
{
StringBuilder buffer = new System.Text.StringBuilder();
foreach (TreeNode rootNode in TreeViewCreateQueries.Nodes)
{
BuildTreeString(rootNode, buffer);
}
File.WriteAllText(saveFileDialog1.FileName, buffer.ToString());
}
}

private void BuildTreeString(TreeNode rootNode, StringBuilder buffer)
{
buffer.Append(rootNode.Text);
buffer.Append(Environment.NewLine);
foreach (TreeNode childNode in rootNode.Nodes)
{
BuildTreeString(childNode, buffer);
}
}

The result is:

Node 1

child 1

child 2

child 3

Node 2

child 1

child 2

the treeview has several subnodes in sub nodes in subnotes etc.



Greatings Hans

Continue reading...
 
Back
Top