Frage : c# treeview Bevölkerung

Zuerst weiß ich, dass der Code nicht elegant ist, aber er… das


I morgens bearbeiten sollte einen Baum von einem DT.
The Papierlösekorotron bevölkernd lässt 3 Spalten/Felder pro row.
1. Lösung Name
2. Tabelle Name
3. Spalte Name

I 3 Nullpunkte verursacht haben. SolutionNode, TableNode, ColumnNode.

The angebrachtes Bild veranschaulicht das result.


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:
6:
37:
38:
39:
40:
CODE Stückchen

    int I = 0;
            foreach (DataRow Reihe 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 = neues TreeNode (Solution_Name);
                TreeNode ColumnNode = neues TreeNode (Column_Name);
                TreeNode TableNode = neues TreeNode (Table_Name);

                wenn (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;
                }

***** Der below Code durchgeführt add, aber das NODE.ADD auftritt nicht tt. 

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

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

                    Previous_Table_Name = Table_Name;
                }

                i++;
            }
Attachments:

Antwort : c# treeview Bevölkerung

oops, über Code doesn ot Arbeit;) Versuch
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 = neues TreeNode („? ");
TreeNode TableNode = neues TreeNode („? ");
TreeNode ColumnNode;

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

  ColumnNode = neues TreeNode (Column_Name);

  wenn (SolutionNode.Text! = Solution_Name) {
    TableNode = neues TreeNode (Table_Name);
    SolutionNode = neues TreeNode (Solution_Name);

    TableNode.Nodes.Add (ColumnNode);
    SolutionNode.Nodes.Add (TableNode);
    treeView1.Nodes.Add (SolutionNode);
  } sonst wenn (TableNode.Text! = Table_Name) {
    TableNode = neues TreeNode (Table_Name);

    TableNode.Nodes.Add (ColumnNode);
    SolutionNode.Nodes.Add (TableNode);
  } sonst, wenn ((SolutionNode.Text == Solution_Name) && (TableNode.Text == Table_Name)) {
    TableNode.Nodes.Add (ColumnNode);
  }
}
Weitere Lösungen  
 
programming4us programming4us