Vraag : treeview bevolking c#

Eerst, weet ik de code niet elegant is maar het zou…


I am moeten werken bevolkend een boom van DT DT.
The heeft 3 kolommen/gebieden per row.
1. Oplossing Name
2. Lijst Name
3. De kolom Name

I heeft tot 3 knopen geleid. SolutionNode, TableNode, beeld ColumnNode.

The in bijlage illustreert result.


" codeBody "
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
CODE

    int. i = 0;
            foreach (rij DataRow in DT.Rows)
            {
                Solution_Name = DT.Rows [I] [0] .ToString ();
                Table_Name = DT.Rows [I] [1] .ToString ();
                Column_Name = DT.Rows [I] [3] .ToString ();

                TreeNode SolutionNode = nieuwe TreeNode (Solution_Name);
                TreeNode ColumnNode = nieuwe TreeNode (Column_Name);
                TreeNode TableNode = nieuwe TreeNode (Table_Name);

                als (Previous_Solution_Name! = Solution_Name)
                {
                    treeView1.Nodes.Add (SolutionNode);
                    SolutionNode.Nodes.Add (TableNode);
                    TableNode.Nodes.Add (ColumnNode);

                    Previous_Solution_Name = Solution_Name;
                    Previous_Table_Name = Table_Name;
                }

***** De onderstaande code wordt uitgevoerd maar NODE.ADD komt niet voor. 

                als ((Previous_Table_Name! = Table_Name) && (Previous_Solution_Name == Solution_Name))
                {
                    SolutionNode.Nodes.Add (TableNode);
                    TableNode.Nodes.Add (ColumnNode);
                }

                als ((Previous_Table_Name == Table_Name) && (Previous_Solution_Name == Solution_Name))
                {
                    TableNode.Nodes.Add (ColumnNode);

                    Previous_Table_Name = Table_Name;
                }

                i++;
            }

Antwoord : treeview bevolking c#

oops, boven het code doesn ot werk;) probeer
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
TreeNode SolutionNode = nieuwe TreeNode („? “);
TreeNode TableNode = nieuwe TreeNode („? “);
TreeNode ColumnNode;

foreach (rij DataRow in DT.Rows) {
  Solution_Name = rij [0] .ToString ();
  Table_Name = rij [1] .ToString ();
  Column_Name = rij [2] .ToString ();

  ColumnNode = nieuwe TreeNode (Column_Name);

  als (SolutionNode.Text! = Solution_Name) {
    TableNode = nieuwe TreeNode (Table_Name);
    SolutionNode = nieuwe TreeNode (Solution_Name);

    TableNode.Nodes.Add (ColumnNode);
    SolutionNode.Nodes.Add (TableNode);
    treeView1.Nodes.Add (SolutionNode);
  } anders als (TableNode.Text! = Table_Name) {
    TableNode = nieuwe TreeNode (Table_Name);

    TableNode.Nodes.Add (ColumnNode);
    SolutionNode.Nodes.Add (TableNode);
  } anders als ((SolutionNode.Text == Solution_Name) && (TableNode.Text == Table_Name)) {
    TableNode.Nodes.Add (ColumnNode);
  }
}
Andere oplossingen  
 
programming4us programming4us