vb.net-树视图未显示正确的selecteditem
我在树视图上选择项目时遇到问题 我有一个构建树视图的函数,包含节点和子节点,当我设置树视图时。selecteditem=somenode,树视图显示为选中的另一个节点的另一个子节点有时是正确的节点,它看起来是随机的 函数如下所示:vb.net-树视图未显示正确的selecteditem,vb.net,treeview,Vb.net,Treeview,我在树视图上选择项目时遇到问题 我有一个构建树视图的函数,包含节点和子节点,当我设置树视图时。selecteditem=somenode,树视图显示为选中的另一个节点的另一个子节点有时是正确的节点,它看起来是随机的 函数如下所示: F.treGrupos.Nodes.Clear() 'build the first level nodes For Each g In m_ModeloGruposSelecciona
F.treGrupos.Nodes.Clear()
'build the first level nodes
For Each g In m_ModeloGruposSeleccionado.Grupos
n = F.treGrupos.Nodes.Add("g" & g.Value.s_IdGrupo.ToString, g.Value.s_IdGrupo.ToString)
Next
'add the subnodes where they belong
For Each Item In m_ConsultaSeleccionada.Indice
If F.treGrupos.Nodes.ContainsKey("g" & Item.Value.IdGrupo) Then
n = F.treGrupos.Nodes("g" & Item.Value.IdGrupo)
n.Nodes.Add("g" & Item.Key.ToString, Item.Value.ItemNodo)
End If
Next
'just testing
F.treGrupos.Refresh()
F.treGrupos.CollapseAll()
F.treGrupos.SelectedNode = Nothing
'm_GrupoSeleccionado has the node i want to select
If m_GrupoSeleccionado > 0 Then
n1 = F.treGrupos.Nodes("g" & m_GrupoSeleccionado.ToString)
Debug.Print(n1.Name) 'ok here
If Not n1 Is Nothing Then
F.treGrupos.SelectedNode = n1
n1.ExpandAll()
End If
Debug.Print(F.treGrupos.SelectedNode.Name) 'ok here too!!??
End If
debug.print似乎打印了正确的节点。如果m_GrupoSeleccionado=3,它将打印g3,即存在的节点。但树状视图显示选定的蓝色背景任意随机子节点;甚至连一个节点都没有!,属于g1或g4。这似乎发生在m_GrupoSeleccionado的任何值上
有什么想法吗
问候 F来自哪里?此代码是否在工作线程上运行?嗨!谢谢你的回答!F是一个表单,在模块上声明。这不是在线程上运行的。