I have started getting an exception thrown when trying to select a child node.
The Treeview is fillled with a company and child nodes are entered, when a specific child node is being entered it is selected with:
= idprealert Then
tvwPreAlert.SelectedNode = tvwNodeChild ' exception here
eption was unhandled
Message=Collection was modified; enumeration operation may not execute.
A first guess is my logic is wrong in filling the child nodes and also selcting one in the list. If that is so then the other way to do it would be to finish filling the treeview then loop through companies/child nodes to select the required one.
If I had to loop through the treeview what would be the syntax to do that correctly?
Dim company2 As Company
Dim tvwNodeCompany As TreeNode
Dim tvwNodeChild As TreeNode
For Each company2 In companyArray
tvwNodeCompany = tvwPreAlert.Nodes.Add(company2.CompanyLedgerType + " ~ " + company2.CompanyName)
tvwNodeCompany.Tag = company2.CompanyID.ToString()
tvwNodeCompany.ForeColor = Color.Blue
Dim prealert1 As PreAlertNumber
For Each prealert1 In company2.CompanyPreAlerts
tvwNodeChild = tvwPreAlert.Nodes(companyArray.IndexOf(company2)).Nodes.Add("Pre-alert " + prealert1.PreAlertID)
tvwNodeChild.Tag = prealert1.PreAlertID
If CLng(prealert1.PreAlertID) = idprealert Then
tvwPreAlert.SelectedNode = tvwNodeChild