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

Item loose Checked state after dragNdrop

4 Answers 110 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 18 Dec 2008, 04:20 PM
Hello Telerik team,

I have a treeview control defined as follows:

<telerikNavigation:RadTreeView  
            x:Name="scOptionsColumnsToShowDnD" MinHeight="50" 
            BorderBrush="Black" 
            BorderThickness="2" 
            IsLineEnabled="False" 
            IsOptionElementsEnabled="True" 
            IsTriStateMode="True" 
            IsEditable="False" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Top" 
            IsDragDropEnabled="True" 
            IsDropPreviewLineEnabled="True" 
            IsDragPreviewEnabled="True" 
            ItemsOptionListType="CheckList" 
            ItemsSource="{Binding}">                                         
</telerikNavigation:RadTreeView>  



If I drag and drop an item which is checked and drop it anywhere else in the treeview the checked state is lost.

How do I keep the checked-state?
Am I missing something?


I also have a problem with data binding  - How do I bind an object property to the checked state?
e.g. I have an object as follows:
public class ColumnName : INotifyPropertyChanged { 
 
        private bool _isSelected = false
        public bool IsSelected { 
            get { return this._isSelected; } 
            set { 
                this._isSelected = value
                if (this.PropertyChanged != null) { 
                    this.PropertyChanged(this, new PropertyChangedEventArgs("IsSelected")); 
                } 
            } 
        } 
 
        public string Name { get; set; } 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
    } 

I want to bind an ObservableCollection<ColumnName> to the treeview.
I already have bound the property "Name" to the treeview display name (with DisplayMemberPath = "Name"), but I also want to bind the property "IsSelected" (in a TwoWay-Mode) to the checked-state of the treeview item.

Do you know how to do this?


Thank you in advance for your time!

Greetings,
Stefan

4 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 20 Dec 2008, 03:50 PM
Hello Stefan,

About your first question - I see that you set the IsTriStateMode to True. When you drag/drop items the checked state is dependant from the target location where you drop the item with the IsTriStateMode is set to true. If the parent item is checked the dragged item will be checked too and vice versa. I'm cuirous to know what you think should be the correct behavior of the CheckedState property when the IsTriStateMode is set to true. Please let us know.

About the binding of the IsSelected property to the CheckState. You can use the ItemPrepared event of the RadTreeView and to set the binding there. You will need to use the Binding with a converter, because your property is a Boolean and the CheckState is of type ToggleState. Let me know if you need some more help on this. See the help topic for ItemPrepared event:
http://www.telerik.com/help/silverlight/telerik.windows.controls.navigation-telerik.windows.controls.radtreeview-itemprepared_ev.html


Regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Valentin.Stoychev
Telerik team
answered on 20 Dec 2008, 03:51 PM
Hello Stefan,

About your first question - I see that you set the IsTriStateMode to True. When you drag/drop items the checked state is dependant from the target location where you drop the item with the IsTriStateMode is set to true. If the parent item is checked the dragged item will be checked too and vice versa. I'm cuirous to know what you think should be the correct behavior of the CheckedState property when the IsTriStateMode is set to true. Please let us know.

About the binding of the IsSelected property to the CheckState. You can use the ItemPrepared event of the RadTreeView and to set the binding there. You will need to use the Binding with a converter, because your property is a Boolean and the CheckState is of type ToggleState. Let me know if you need some more help on this. See the help topic for ItemPrepared event:
http://www.telerik.com/help/silverlight/telerik.windows.controls.navigation-telerik.windows.controls.radtreeview-itemprepared_ev.html

This example can also be of help:
http://demos.telerik.com/silverlight/#TreeView/BindingToDataItemProperties

Regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andreas
Top achievements
Rank 1
answered on 22 Dec 2008, 04:42 PM
Hello Valentin,

Thank you for your answers!

In my opinion the checked state should remain the same after drag and drop. For example if you check an item and drag it to another place you have to select it again after it has been dropped somewhere else. Especially if it is dropped at the same hierarchical level you may want to keep the checked state (to only do a reorder of the RadTreeView).

On the other hand it could be useful to inherit the checked state (as you described) - why not make this configurable with a new property (e.g. "InheritCheckedState" or something like that).
If the property is set to true it matches your description. Otherwise it keeps the state it already has and the programmer has the responsibility to change the state if needed (the event ItemPrepared is fired to handle this, right?).

For example I want to use the RadTreeView to select the columns of a result list. The column names are listed in the RadTreeView and you check the columns you want to be listed AND you select the order of the columns in the result list by drag and drop them in the TreeView in the correct order.
Therefore I want to keep the checked state after an element is dropped ( I don't use hierarchy - only a flat list).


Thank you for the hint with the ItemPrepared to bind the CheckedState to my object ColumnName. But it is done only once for all objects in the beginning or if an item is dragged.
I have only one problem - If I change the ColumnName.IsSelected property of my object the UI of the RadTreeView is not updated and I have not found a way to select the correspondent RadTreeViewItem to change the CheckedState.

Do you know how I can change the CheckedState of a RadTreeViewItem if I know its bound object ColumnName?
I tried to add an event handler of the INotifyPropertyChanged of my ColumnName-object, but then I have the object and I can't get the RadTreeViewItem to change the CheckedState accordingly.


For the RadTreeView there is a property "CheckedItems". It would come in very handy to have a property "UnCheckedItems", which is the opposite of the "CheckedItems".

An idea of a new feature for the RadTreeView:
To sort all checked RadTreeViewItems at the top/bottom of the RadTreeView. So if I check an item it is automatically moved to the other checked items at the top/bottom of the RadTreeView (at the same hierarchy of course).


Greetings,
Stefan



0
Valentin.Stoychev
Telerik team
answered on 06 Jan 2009, 05:15 PM
Hi Stefan,

First of all sorry for the delayed answer!

You have a point about the CheckState property and the drag and drop. We will need to think about what is the best way to do it. Maybe the option to add another property will be choosen. Stay tuned on that for a solution.

About the second issue with the checked state and IsSelected property of your data object - in the ItemPrepared event are you making a new binding or you just set the CheckState property once? If you do a binding I think you should get the automatic update.

Thanks for the other suggestions too. We will have them in mind when do the next update of the control.

Regards,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Andreas
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or