Hello SSirica,
Please ensure that the ID you are passing to the Node is the correct one and also the node you are checking has the ComboBox as a child control. You can use the Quick Watch(F9) of Visual Studio to inspect the node once you hit the breakpoint.
Here is the code that gets the ComboBoxes properly:
<telerik:RadButton runat="server" ID="RadButton1" Text="Get Selection" AutoPostBack="true" OnClick="RadButton1_Click" />
<telerik:RadTreeView ID="tvProcInst" runat="server" CheckBoxes="True" CausesValidation="False"
DataTextField="LEVEL_NAME" DataValueField="LEVEL_CODE" RenderMode="Lightweight"
CssClass="Left" MultipleSelect="True" OnNodeDataBound="tvProcInst_NodeDataBound">
</telerik:RadTreeView>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
tvProcInst.DataSource = Enumerable.Range(1, 5).[Select](Function(x) New With {Key
.LEVEL_CODE = x, Key
.LEVEL_NAME = "Node #" & x
})
tvProcInst.DataBind()
End If
End Sub
Public Function GetCB(ByVal id As String) As RadComboBox
Dim cb = New RadComboBox()
cb.ID = id & "_ComboBox"
cb.Items.Add(New RadComboBoxItem() With {
.Text = "Item 1",
.Value = "1"
})
cb.Items.Add(New RadComboBoxItem() With {
.Text = "Item 2",
.Value = "2"
})
Return cb
End Function
Public Sub tvProcInst_NodeDataBound(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)
Dim cn As RadTreeNode
cn = New RadTreeNode()
cn.Controls.Add(GetCB(e.Node.Value.ToString()))
cn.Checkable = False
e.Node.Nodes.Add(cn)
End Sub
Protected Sub RadButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
For Each node As RadTreeNode In tvProcInst.GetAllNodes().Where(Function(x) x.Checkable = False)
Dim cb = TryCast(node.FindControl(node.ParentNode.Value & "_ComboBox"), RadComboBox)
Next
End Sub
Depending on the GetCB method, you should use the same value that you have used for generating the ComboBox id.
Another thing worth mentioning is that you are passing the Parent node value to the GetCB method while you are trying to find the ComboBox via the unique ID of the combobox container node.
Also, the Nodes collection of the TreeView contains only the root nodes, while the TreeView.GetAllNodes() method returns all nodes in the treeview.
Regards,
Peter Milchev
Progress Telerik
Progress is here for your business, like always.
Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.