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

Node.ShowCheckBox = false does not always work properly

4 Answers 116 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Claude asked on 03 Aug 2010, 05:44 AM
I decided that it would be easier to control everything if I built my treeview by hand, one node at a time.  I wanted to suppress checkbox display on all levels of the tree but the lowest level.  However, even though I set ShowCheckBox = false for all levels, it does not suppress the checkboxes at the highest level of the tree.  Otherwise, the tree renders perfectly.  I tried setting tShowCheckBox to false for the lowest level, and that worked.  Is this a bug, and if so, is there a workaround?  Can anyone suggest how to make this work?

Here is the code:

private void BuildTreeFromBindingSourceData()
      {
          this.monitorRadTreeView.Nodes.Clear();
 
          int companyBindingSourcePosition;
          int plantCompanyBindingSourcePosition;
          int equipmentPlantBindingSourcePosition;
 
          RadTreeNode companyNode;
          RadTreeNode plantNode;
          RadTreeNode equipmentNode;
 
          if (companyBindingSource.Count > 0)
          {
              companyBindingSourcePosition = 0;
              while (companyBindingSourcePosition < companyBindingSource.Count)
              {
                  companyBindingSource.Position = companyBindingSourcePosition;
                  companyNode = new RadTreeNode();
                  companyNode.Text = ((MonitorInterfaceDBDataSet.CompanyRow) ((DataRowView)companyBindingSource.Current).Row).Name;
                  companyNode.Tag = ((MonitorInterfaceDBDataSet.CompanyRow)((DataRowView)companyBindingSource.Current).Row).ID;
                  companyNode.ShowCheckBox = false;
 
                  if (plantCompanyBindingSource.Count > 0)
                  {
                      plantCompanyBindingSourcePosition = 0;
                      while (plantCompanyBindingSourcePosition < plantCompanyBindingSource.Count)
                      {
                          plantCompanyBindingSource.Position = plantCompanyBindingSourcePosition;
                          plantNode = new RadTreeNode();
                          plantNode.Text = ((MonitorInterfaceDBDataSet.PlantRow)((DataRowView)plantCompanyBindingSource.Current).Row).Name;
                          plantNode.Tag = ((MonitorInterfaceDBDataSet.PlantRow)((DataRowView)plantCompanyBindingSource.Current).Row).ID;
                          plantNode.ShowCheckBox = false;
 
                          if (equipmentPlantBindingSource.Count > 0)
                          {
                              equipmentPlantBindingSourcePosition = 0;
                              while (equipmentPlantBindingSourcePosition < equipmentPlantBindingSource.Count)
                              {
                                  equipmentPlantBindingSource.Position = equipmentPlantBindingSourcePosition;
                                  equipmentNode = new RadTreeNode();
                                  equipmentNode.Text = ((MonitorInterfaceDBDataSet.EquipmentRow)((DataRowView)equipmentPlantBindingSource.Current).Row).Name;
                                  equipmentNode.Tag = ((MonitorInterfaceDBDataSet.EquipmentRow)((DataRowView)equipmentPlantBindingSource.Current).Row).ID;
                                  equipmentNode.ShowCheckBox = true;
                                  plantNode.Nodes.Add(equipmentNode);
                                  equipmentPlantBindingSourcePosition++;
                              }
                          }
                          companyNode.Nodes.Add(plantNode);
                          plantCompanyBindingSourcePosition++;
                      }
                  }
                  this.monitorRadTreeView.Nodes.Add(companyNode);
                  companyBindingSourcePosition++;
              }
          }
      }


The binding sources, if you need to see them, look like:

           
companyBindingSource = new BindingSource();
companyBindingSource.DataSource = monitorInterfaceDBDataSet;
companyBindingSource.DataMember = "Company";
 
plantCompanyBindingSource = new BindingSource();
plantCompanyBindingSource.DataSource = companyBindingSource;
plantCompanyBindingSource.DataMember = "FK_Plant_Company";
 
equipmentPlantBindingSource = new BindingSource();
equipmentPlantBindingSource.DataSource = plantCompanyBindingSource;
equipmentPlantBindingSource.DataMember = "FK_Equipment_Plant";

4 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 06 Aug 2010, 10:00 AM
Hello Claude,

Thank you for writing.

I have attached a sample application that demonstrates how the checkboxes are hidden on arbitrary levels. If your application does not work like this, please send a sample project that showcases the undesired behavior.

I am looking forward to your reply.
 
All the best,
Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Claude
Top achievements
Rank 1
answered on 10 Aug 2010, 05:59 AM
This would not let me attach my modified version of your project as a zip file, so I tried to attach it as a jpg.  That didn't work either.  The following can be pasted into your sample code to make a working program.  I don't know any other way to reply.

The problem is still there, though I did figure out a fix of my own.  I still think my code shows that there is a bug in the Telerik tree object, though I admit that the exercise of creating a simple version for demonstration made it easier to figure out the fix.

I will show the code here so you can see what I mean, just in case the attachment doesn't work out.  This is the entire program, minus the creation of a form.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        RadTreeView treeView = new RadTreeView();

        
public Form1()
        {
            InitializeComponent();
  
            treeView.CheckBoxes = true;
            treeView.Dock = DockStyle.Fill;
            this.Controls.Add(treeView);
  
            RadTreeNode grandparent;
            RadTreeNode parent;
            RadTreeNode child;
  
            /// In my application, I build the tree from binding sources.  I have to do
            /// it the way shown below to keep the data properly in sync.
            for (int i = 0; i < 2; i++)
            {
                grandparent = new RadTreeNode();
                grandparent.Text = "Grandparent " + (i + 1).ToString();
                // Even though this is set to false, it has no effect
                // on the output... the checkboxes appear
                grandparent.ShowCheckBox = false;
  
                for (int j = 0; j < 2; j++)
                {
                    parent = new RadTreeNode();
                    parent.Text = "Parent " + (j + 1).ToString();
                    parent.ShowCheckBox = false;
  
                    for (int k = 0; k < 1; k++)
                    {
                        child = new RadTreeNode();
                        child.Text = "Child " + (k + 1).ToString();
                        child.ShowCheckBox = true;
  
                        parent.Nodes.Add(child);
                    }
                    grandparent.Nodes.Add(parent);
                }
                treeView.Nodes.Add(grandparent);
            }
  
  
            // Because I did this exercise for you, it was easier to
            // figure out a fix.  However, I still think that my 
            // problem is the result of an error in the Telerik code
            // somewhere, and my fix is a band-aid.
  
  
            // this code fixes the problem, but it seems like a hack, 
            // because I already set the ShowCheckBox property to false
                 // when I created the nodes.
  
            //int n = 0;
            //foreach (RadTreeNode node in treeView.Nodes)
            //{
            //    treeView.Nodes[n].ShowCheckBox = false;
            //    n++;
            //}
  
            treeView.ExpandAll();
        }
    }
}


0
Victor
Telerik team
answered on 12 Aug 2010, 07:44 PM
Hello Claude,

Thank you for writing.

I believe the issue you are describing occurs in your code because you are setting the ShowCheckBox property before you add a node to the treeview. After you add the node, the treeview most likely overwrites the value you set since it has no notion of property value composition, the ShowCheckBoxes property is not a RadProperty. It is great that you found a workaround however.

Please write again if you need further assistance.

Kind regards,
Victor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stefan
Telerik team
answered on 22 Mar 2011, 03:18 PM
Hi Claude,

Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.

Best wishes,
Stefan
the Telerik team
Tags
Treeview
Asked by
Claude
Top achievements
Rank 1
Answers by
Victor
Telerik team
Claude
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or