This is a migrated thread and some comments may be shown as answers.

different items in combobox drop down

2 Answers 30 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 2
Andy Green asked on 30 Oct 2013, 09:55 PM
Hi

Just thinking out loud here, I have a radComboBox with a tree view inside, We have to add another selection criteria on an already busy form, I'm wondering if its possible to put a few (only 3-4) checkboxes above the tree view all enclosed in a RadCombobox. The tree view would be populated based on which check box was selected.

Andy

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 31 Oct 2013, 03:53 AM
Hi Andy Green,

Please have a look into the following code snippet  to populate a RadTreeView based on the selected CheckBox.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" Height="200" >
    <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" Text="Node1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
        <asp:CheckBox ID="CheckBox2" Text="Node2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged" />
        <telerik:RadTreeView ID="RadTreeView1" runat="server" Visible="false">
            <Nodes>
                <telerik:RadTreeNode Text="Node1" runat="server" Visible="false">
                    <Nodes>
                        <telerik:RadTreeNode Text="Node1.1" runat="server">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode Text="Node1.2" runat="server">
                        </telerik:RadTreeNode>
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Node2" runat="server" Visible="false">
                    <Nodes>
                        <telerik:RadTreeNode Text="Node2.1" runat="server">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode Text="Node2.2" runat="server">
                        </telerik:RadTreeNode>
                    </Nodes>
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeView>
    </ItemTemplate>
    <Items>
        <telerik:RadComboBoxItem Text=""></telerik:RadComboBoxItem>
    </Items>
</telerik:RadComboBox>

C#:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    CheckBox chk = (CheckBox)RadComboBox1.Items[0].FindControl("CheckBox1");
    String checkedtext = chk.Text;
    RadTreeView tree = (RadTreeView)RadComboBox1.Items[0].FindControl("RadTreeView1");
    tree.Visible = true;
    RadTreeNode node = (RadTreeNode)tree.FindNodeByText(checkedtext);
    if (chk.Checked == true)
    {
        node.Visible = true;
        node.Expanded = true;
    }
    else
    {
        node.Visible = false;
        node.Expanded = false;
    }
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
    CheckBox chk = (CheckBox)RadComboBox1.Items[0].FindControl("CheckBox2");
    String checkedtext = chk.Text;
    RadTreeView tree = (RadTreeView)RadComboBox1.Items[0].FindControl("RadTreeView1");
    tree.Visible = true;
    RadTreeNode node = (RadTreeNode)tree.FindNodeByText(checkedtext);
         
    if (chk.Checked == true)
    {
        node.Visible = true;
        node.Expanded = true;
    }
    else
    {
        node.Visible = false;
        node.Expanded = false;
    }
}

Thanks,
Princy.
0
Andy Green
Top achievements
Rank 2
answered on 31 Oct 2013, 09:52 AM
Thanks Princy

To be honest I wasn't looking forward to this development, but getting excited now.

Andy
Tags
ComboBox
Asked by
Andy Green
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Andy Green
Top achievements
Rank 2
Share this question
or