different items in combobox drop down

3 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 30 Oct 2013 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Oct 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 31 Oct 2013 Link to this post

    Thanks Princy

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

    Andy
Back to Top