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

How to bind the check-boxes to support TriStateMode?

3 Answers 67 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Veteran
Steve asked on 16 Dec 2019, 06:47 AM

I have a Business Object just like:

private class Employee
            {
            public int EmployeeID { get;set;}
            public int ManagerID { get;set;}
            public string Title {get;set;}

            public bool IsChecked { get; set; } = false;
    
            }

binding like this:

            List<Employee> employees = new List<Employee> {.......};

            radTreeView1.DataSource = employees;
            radTreeView1.DisplayMember = "Title";
            radTreeView1.ParentMember = "ManagerID";
            radTreeView1.ChildMember = "EmployeeID";
            radTreeView1.CheckedMember = "IsChecked";

when I toggle the tree node , the application throw an expection.

So,

what is the correct way to binding check-boxes on tristatemode ?

 

3 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 16 Dec 2019, 03:56 PM

Hello Steve,

I suppose that you already have set the TriStateMode mode property to true in your project. As I can see from your code snippet the IsChecked property from the Employee class is defined to accept a boolean value only, it is not defined to accept null values. When you try to change the state of the checkbox an exception is thrown because the null value cannot be converted to boolean type. In order to avoid this, I modified the IsChecked property in a way to accept null values:

this.radTreeView1.TreeViewElement.TriStateMode = true;
public class Employee
    {
        public int EmployeeID { get; set; }
        public int ManagerID { get; set; }
        public string Title { get; set; }

        public bool? IsChecked { get; set; } = false;
    }

The following thread is useful on this topic: https://stackoverflow.com/questions/5362437/assign-null-value-to-boolean-variable

I hope this helps. Let me know if you have additional questions.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Steve
Top achievements
Rank 1
Veteran
answered on 18 Dec 2019, 01:24 AM

It works fine on version 2019. But, unfortunately, I works on the version 2017, it not works. And there is another problem , I changed the type of IsChecked to ToggleState in order to use tristatemode, but intermidate status not works. Code snippet just like,

Business Object,

    public class Employee
        {
        public string Name { get; set; }
        public int ID { get; set; }
        public int ManagerID { get; set; }
        public ToggleState IsChecked { get; set; }
        }

Binding,

   List<Employee> employees = new List<Employee>
                {
                new Employee {Name ="A", ID = 1, ManagerID = -1 },
                new Employee {Name ="B1", ID = 2, ManagerID = 1},
                new Employee {Name ="B2", ID = 3, ManagerID = 1},
                new Employee {Name ="C1", ID = 4, ManagerID = 2},
                };

            radTreeView1.ParentMember = "ManagerID";
            radTreeView1.DisplayMember = "Name";
            radTreeView1.ChildMember = "ID";
            radTreeView1.CheckedMember = "IsChecked";
            radTreeView1.DataSource = employees;

 

do you know where is wrong and how can i correct it, very thanks!

0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 18 Dec 2019, 11:50 AM

Hello Steve,

RadTreeViw supports TriStateMode when binding checkboxes since R3 2017(version 2017.3.912). If you are using an older version you shouldn't be able to benefit from the introduced functionality. I have tested the provided code snippet with the specified version 2017.3.912 and it works fine. If you have a parent node, and 2 child nodes, then check one of the child nodes and the parent node state becomes intermediate, showing that only some of the children are checked. You can see in the attached gif file.

This is why I will recommend you to upgrade to one of the latest version. Thus, you can benefit from all of the introduced improvements and new features that are available in the new versions.

However, I have found out the feedback item logged in our Feedback portal as well. You can refer to it here. Please, feel free to use the suggested workaround there if it is suitable for you.

I hope this information helps.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Treeview
Asked by
Steve
Top achievements
Rank 1
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Steve
Top achievements
Rank 1
Veteran
Share this question
or