I have some trouble managing a treeview the right way. I have a DataGridView and some columns in it. One column shows an ID, the second one a sequence number (one ID can have multiple sequence numbers - for exmple the ID 1000 has the sequence numbers 1,2 and 3). Now I want the user to select certain rows in the datagridview and then fill a treeview the right way. The code:
foreach (DataGridViewColumn column in form1.dataGridView.Columns)
datTable.Columns.Add(column.Name);
for (int i = 0; i < form1.dataGridView.SelectedRows.Count; i++)
{
datTable.Rows.Add();
for (int j = 0; j < form1.dataGridView.Columns.Count; j++)
{
datTable.Rows[i][j] = form1.dataGridView.SelectedRows[i].Cells[j].Value;
}
}
for (int i = 0; i < datTable.Rows.Count;i++ )
{
TreeNode node = new TreeNode(datTable.Rows[i][form1.cusIdBox.Text].ToString());
node.Nodes.Add(datTable.Rows[i][form1.seqNrBox.Text].ToString());
treeView1.Nodes.Add(node);
}
This just takes the selected rows and puts them into a datatable. Then each ID gets a node and the sequence number as childnode. What I want to do is:
When I take the example from above - the user selects a row with the ID 1000 where the sequence number is '1'. Now I want to add automatically every other row that has the ID 1000 to my datatable (so three rows with ID 1000 and sequence numbers 1,2 and 3) and then just add a node '1000' with childnodes '1', '2' and '3'. How to do that?
Aucun commentaire:
Enregistrer un commentaire