v-jetan
2/17/2004 5:41:00 AM
Hi Zarko,
Thank you for posting in the community!
Based on my understanding, all your treeview control's items have checkbox.
You use DropDownList control to fire event and retrieve data from the
database. Then checked the checkbox through the data. But at last, only one
item is checked.(Last Item)
=========================================
In your code, I did not see anything incorrect. I think you should paste
all the code snippet to reproduce your problem.
I do the test project like this:
<asp:DropDownList id="DropDownList1" runat="server" Width="160px"
Height="40px" AutoPostBack="True">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>
<iewc:TreeView id="TreeView1" runat="server" Width="240px" Height="264px">
<iewc:TreeNode NodeData="1" CheckBox="True" Text="Node0">
<iewc:TreeNode NodeData="3" CheckBox="True" Text="Node0">
<iewc:TreeNode NodeData="2" CheckBox="True" Text="Node2"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode NodeData="3" CheckBox="True" Text="Node1"></iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode NodeData="1" CheckBox="True" Text="Node1">
<iewc:TreeNode NodeData="2" CheckBox="True" Text="Node3">
<iewc:TreeNode NodeData="3" CheckBox="True"
Text="Node4"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeNode>
<iewc:TreeNode NodeData="2" CheckBox="True" Text="Node2">
<iewc:TreeNode NodeData="3" CheckBox="True" Text="Node5">
<iewc:TreeNode NodeData="2" CheckBox="True" Text="Node3"></iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>
Then, in code behind:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim val As String = DropDownList1.SelectedValue
Dim i, j, k As Integer
For i = 0 To TreeView1.Nodes.Count - 1
For j = 0 To TreeView1.Nodes(i).Nodes.Count - 1
If TreeView1.Nodes(i).Nodes.Item(j).NodeData = val Then
TreeView1.Nodes(i).Nodes.Item(j).Checked = True
Else
TreeView1.Nodes(i).Nodes.Item(j).Checked = False
End If
For k = 0 To TreeView1.Nodes(i).Nodes.Item(j).Nodes.Count -
1
If
TreeView1.Nodes(i).Nodes.Item(j).Nodes.Item(k).NodeData = val Then
TreeView1.Nodes(i).Nodes.Item(j).Nodes.Item(k).Checked = True
Else
TreeView1.Nodes(i).Nodes.Item(j).Nodes.Item(k).Checked = False
End If
Next
Next
Next
End Sub
In the code, I check all the nodes whoes NodeData are the same as the
selected value in dropdownlist.(Except the first level nodes)
In your code, I modified ID property to NodeData property, because in a web
page, the ID property must be unique. (Is this your problem?)
=======================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.