I have a tree of a depth of 2 as follows.
Module 1
Form 1
Tab 1
Form 2
Tab 2
Tab 3
Form 2
Tab 2
Tab 3
Module 2
Form 4
Tab 2
Form 5
Tab 4
Tab 5
Tab 6
Form 5
Tab 4
Tab 5
Tab 6
Form 5
Tab 4
Tab 5
Tab 6
As shown above, the problem is that, the Forms
will be displayed as many times as the Tabs
they have. For example, if Form 5
has three Tabs
, it will be displayed thrice.
I need them to be displayed just once since their tabs are the same.
This is my code:
private void LoadTreeview()
{
string sql = "SELECT Module, Form, Tab, HelpText " +
"FROM PageHelp " +
"WHERE Module IS NOT NULL";
DataTable dt = Public_Methods.Get_DataTable(sql);
DataView dvModules = new DataView(dt, "Module IS NOT NULL", "Module ASC", DataViewRowState.Unchanged);
DataTable dtModules = dvModules.ToTable(true, "Module");
for (int count = 0; count < dtModules.Rows.Count; count++)
{
TreeNode TModule = new TreeNode();
TModule.Value = dtModules.Rows[count]["Module"].ToString();
TModule.Text = dtModules.Rows[count]["Module"].ToString();
TModule.Collapse();
LoadForms(ref TModule, dt);
TreeView_EditHelp_Help.Nodes.Add(TModule);
}
}
private void LoadForms(ref TreeNode TModule, DataTable dt)
{
DataRow[] drForms = dt.Select("Module='" + TModule.Value + "'");
for (int count = 0; count < drForms.Length; count++)
{
TreeNode TForm = new TreeNode();
TForm.Value = drForms[count]["Form"].ToString();
TForm.Text = drForms[count]["Form"].ToString();
TForm.Collapse();
LoadTabs(ref TForm, dt);
TModule.ChildNodes.Add(TForm);
}
}
private void LoadTabs(ref TreeNode TForm, DataTable dt)
{
DataRow[] drTabs = dt.Select("Form='" + TForm.Value + "'");
for (int count = 0; count < drTabs.Length; count++)
{
TreeNode TTab = new TreeNode();
TTab.Value = drTabs[count]["Tab"].ToString();
TTab.Text = drTabs[count]["Tab"].ToString();
TTab.Collapse();
TForm.ChildNodes.Add(TTab);
}
}
Any assistance please?