ARandomBro
New Member
I'm trying to add nodes to a TreeView object and I've got the following code that's reading the data from a MySqlDataReader object:\[code\]while (no_child_rdr.Read()){ TreeNode parentNode; int position = no_child_rdr.GetInt16("position"); // See if the node for this category already exists try { parentNode = DocumentsTree.Nodes[position]; } catch (Exception ex) { string category = no_child_rdr.GetString("cat_name"); parentNode = new TreeNode(category, category); DocumentsTree.Nodes.AddAt(position, parentNode); >> This is where my error occurs } } no_child_rdr.Close();\[/code\]The error I end up with is:\[code\]Index must be within the bounds of the List.Parameter name: index\[/code\]I'm obviously laboring under the false assumption that I can stick a new \[code\]TreeNode\[/code\] at any arbitrary place in the \[code\]TreeNodeCollection\[/code\] using \[code\]Nodes.AddAt()\[/code\]. Seeing as these objects have a position defined in the database, how should I go about building the \[code\]TreeNodeCollection\[/code\] such that my nodes are properly ordered?