Advertisement
Ambicatus

Pretvorba treeview to datatable

Jun 4th, 2020
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. int onceMore = 0;
  2.             for (int i = 0; i < Nodes.Nodes.Count; i++)
  3.             {
  4.                 var activeNode = Nodes.Nodes[i];
  5.                 var numberOfColumns = activeNode.Nodes.Count * 2 + 1;
  6.                 //var row = new Object[activeNode.Nodes.Count];
  7.                 dataGridView1.ColumnCount = numberOfColumns;
  8.                 dataGridView1.RowCount = activeNode.Nodes.Count;
  9.             OnceAgain:
  10.                 onceMore++;
  11.                 for (int j = 0; j < activeNode.Nodes.Count; j++)
  12.                 {
  13.                     if (onceMore == 1)
  14.                     {
  15.                         dataGridView1.Columns[j].Name = activeNode.Nodes[j].Text;
  16.                         dataGridView1.Rows[j].HeaderCell.Value = activeNode.Nodes[j].Text;
  17.                     }
  18.                     else
  19.                     {
  20.                         var index = j + (activeNode.Nodes.Count - j) + j;
  21.                         dataGridView1.Columns[index].Name = activeNode.Nodes[j].Text + " Koristnost";
  22.                     }
  23.                     if (onceMore < 2 && j == activeNode.Nodes.Count - 1)
  24.                     {
  25.                         goto OnceAgain;
  26.                     }
  27.  
  28.                     if (j == activeNode.Nodes.Count - 1)
  29.                     {
  30.                         dataGridView1.Columns[numberOfColumns - 1].Name = "Weights";
  31.                     }
  32.                 }
  33.  
  34.                 for(int row=0; row < dataGridView1.RowCount; row++)
  35.                 {
  36.                     for(int column = 0; column < dataGridView1.ColumnCount; column++)
  37.                     {
  38.                         if(row == column)
  39.                         {
  40.                             dataGridView1[row, column].Value = 1;
  41.                             dataGridView1[row, column].ReadOnly = true;
  42.                         }
  43.                     }
  44.                 }
  45.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement