Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:14:13+00:00 2026-06-12T05:14:13+00:00

I need to create a treeview control with checkboxes. However, my treeview needs to

  • 0

I need to create a treeview control with checkboxes. However, my treeview needs to have checkboxes for the parent and the child. The business logic in my situation is that the user may choose “MS Office” but may not want “Microsoft”.

I came across asp.net TreeView: how to use CheckBox in TreeView which helps, however, I can’t seem to create a checkbox for “Microsoft” & “Adobe” nodes. How would I go about doing that?

enter image description here

The html code is:

<form id="form1" runat="server">  
    <div>  
    <h2 style="color:Green">TreeView: ShowCheckBoxes</h2>  
        <asp:Label   
            ID="Label1"   
            runat="server"   
            Text="Checked Favorite"  
            Font-Size="Medium"  
            ForeColor="SeaGreen"  
            Font-Italic="true"  
            >  
        </asp:Label>  
        <br /><br />  
        <asp:TreeView   
            ID="TreeView1"  
            runat="server"  
            DataSourceID="XmlDataSource1"  
            >  
            <DataBindings>  
                <asp:TreeNodeBinding DataMember="Products" Text="Products" />  
                <asp:TreeNodeBinding DataMember="Type" TextField="Name" />  
                <asp:TreeNodeBinding DataMember="Product" TextField="Name" ValueField="ID" />  
            </DataBindings>  
        </asp:TreeView>  
        <br />  
        <asp:XmlDataSource   
            ID="XmlDataSource1"  
            runat="server"  
            >  
            <Data>  
                <Products>  
                    <Type Name="Microsoft">  
                        <Product ID="1" Name="MS Office"/>  
                        <Product ID="2" Name="ASP.NET"/>  
                    </Type>  
                    <Type Name="Adobe">  
                        <Product ID="1" Name="ColdFusion"/>  
                        <Product ID="2" Name="Flex"/>  
                        <Product ID="2" Name="Photoshop"/>  
                    </Type>  
                </Products>  
            </Data>  
        </asp:XmlDataSource>  
        <asp:Button ID="Button1" runat="server" Text="Submit Favorite" OnClick="Button1_Click" />  
    </div>  
    </form>  

The code behind is:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace TreeviewCheckboxSample
{
    public partial class Treeview : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "Your favorite:";
            if (TreeView1.CheckedNodes.Count > 0)
            {
                foreach (TreeNode node in TreeView1.CheckedNodes)
                {
                    Label1.Text += "<br />" + node.Text.ToString();
                }
            }
            else
            {
                Label1.Text = "Checked before submit.";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                TreeView1.ShowCheckBoxes = TreeNodeTypes.Leaf;
                TreeView1.ForeColor = System.Drawing.Color.Black;
                TreeView1.BackColor = System.Drawing.Color.White;
                TreeView1.Width = 200;
                Button1.Font.Bold = true;
                Button1.ForeColor = System.Drawing.Color.Crimson;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:14:15+00:00Added an answer on June 12, 2026 at 5:14 am

    The ShowCheckBoxes property doesn’t really cover this case.

    However, you can change the ShowCheckBox property on each individual node after the tree is bound. That page contains some example code that even does it based on the node’s depth, which looks like what you’re after.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WinForm TreeView Control that displays the Parent Child relationship of CaseNotes(I
I need to create a TreeView type controller that will display rich text. Example:
Background: I have a custom user control based around a WPF TreeView. I've been
I've been asked to create a new control for a feature that we need,
I need to create a TreeView in WPF that looks something like this: Admins
I am trying to create a TreeView from the Silverlight TreeView control. I have
I'm working on a project that heavily uses TreeView and TreeNodes. However, I need
I need to create a TreeView that hold synchronized data, like a DataGrid. To
I need to create a program that makes XML editing possible in user-friendly way.
I have the need to create a HierarchicalDataTemplate for a TreeView in code-behind. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.