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

What is the easiest way to bind to the treeview checkbox?

1 Answer 87 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 05 Mar 2010, 12:19 AM
I'm struggling with binding to the checkbox of a tree view item ... I have the following class:

    public class Filter : INotifyPropertyChanged
    {
        public string Key { get; set;}
        public string Name { get; set; }
        public FilterCollection Filters { get; set; }
        
        private bool _count = false;
        public bool Count
        {
            get
            {
                return _count;
            }
            set
            {
                if (_count != value)
                {
                    _count = value;
                    this.NotifyPropertyChanged("Count");
                }
            }
        }

        private bool _isChecked = false;
        public bool IsChecked
        {
            get
            {
                return _isChecked;
            }
            set
            {
                if (_isChecked != value)
                {
                    _isChecked = value;
                    this.NotifyPropertyChanged("IsChecked");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public Filter()
        {
            this.Filters = new FilterCollection();
        }
    }

I have a collection of these objects called FilterCollection of type ObservableCollection<Filter> ... what is the best and easiest way to bind the property IsChecked to the CheckState of the treeview item? 

I'm binding the datasource in the code-behind, if that matters.

Silverlight newbie, my apologies.

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 10 Mar 2010, 11:39 AM
Hello Matt,

Please take a look at the KB article demonstrating the usage of HierarchicalDataTemplate and ContainerBindingCollection in RadTreeView here.

You can also take a look at the example project that I've attached where HierarchicalDataTemplate and ContainerBindingCollection are used in order to data bind the State of the CheckBox of the TreeViewItems to the isSelected property of the business object.

Please let us know if you need more info.

Sincerely yours,
Tina Stancheva
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.
Tags
TreeView
Asked by
Matt
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or