DUBBIO SU TREEVIEW

giovedì 11 gennaio 2007 - 00.05

MATTEHGT Profilo | Junior Member

Ho la seguente problematica: ho la necessità di eliminare lo stato di checked=true ad un nodo figlio selezionato dopo averne selezionato un altro, in sostanza se seleziono un nodo automaticamente si deseleziona quello precedentemente selezionato.

Ho provato con il seguente codice

if e.node.index >0 then
e.node.prevnode.checked=false

Il programma funziona perdelezionando i nodi precedentii a quello selezionato. Il problema è per quelli successivi.
Il codeice sarebbe if e.node.index <(index)
e.node.nextnode.checked=false

Il problema è che non riesco a mettere insieme queste due routine e a far funzionare le due casistiche insieme.

Qualcuno sa darmi un suggerimento?

Grazie

Saluti

maurosegato Profilo | Newbie

Questo ti drovrebbe funzionare..


Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

e.Node.Checked = true

SetTreeNodeCheck(directcast(sender, TreeView).Nodes, e.Node, false)

End Sub

public sub SetTreeNodeCheck(byval nodes as TreeNodeCollection, byval escludeTreeNode as TreeNode, byval state as boolean)

for each n as TreeNode in nodes

SetTreeNodeCheck(n.Nodes, escludeTreeNode, state)

if not n.Equals(escludeTreeNode) andalso not n.Checked = state
n.Checked = state
end if

next

end sub

Mauro Segato

MATTEHGT Profilo | Junior Member

L'HO IMPOSTATA COSI'

Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck


SetTreeNodeCheck(DirectCast(sender, TreeView).Nodes, e.Node, False)


End Sub

Public Sub SetTreeNodeCheck(ByVal nodes As TreeNodeCollection, ByVal escludeTreeNode As TreeNode, ByVal state As Boolean)

For Each n As TreeNode In nodes

SetTreeNodeCheck(n.Nodes, escludeTreeNode, state)

If Not n.Equals(escludeTreeNode) AndAlso Not n.Checked = state Then
n.Checked = state
End If

Next

End sub

Il nuovo nodo su cui metto il check mi esclude il precedente, ma per selezionare il corrente devo fare un altro clic. E' possibile con un solo clic deselezionare il precedente a attivare il corrente?

Grazie

Saluti

Matteo Agrizzi

maurosegato Profilo | Newbie

prova così:

Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck

static last_node_selected as treenode = nothing

if not last_node_selected is nothing then _
last_node_selected.Checked = false

e.Node.Checked = true

last_node_selected = e.Node

End Sub

questo è anche più veloce nell'esecuzione!!!
ciao

Mauro Segato

MATTEHGT Profilo | Junior Member

HO OTTENUTO L'ERRORE ASSICURARSI CHE NON SI TRATTI DI UN CICLO INFINITO O DI UNA RICORSIONE INFINITA
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5