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

checkbox binding

4 Answers 109 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Eric Zeng
Top achievements
Rank 1
Eric Zeng asked on 25 Mar 2010, 10:25 AM
I created a treeview, because I had designated ItemsOptionListType="CheckList", so there is a checkbox next to every node. But I need to check the checkbox according to different datasets(Receiver Object collection), so how can I achieve this feature through binding?
Here is my Class:
 public class Receiver
    {  
        public Receiver() { }  
        [Key]  
        public int AdminId { getset; }  
        public string AdminName { getset; }  
        public int TeamId { getset; }  
        public string TeamName { getset; }  
    }  
 
 

Here is my tree:

<riaControls:DomainDataSource x:Name="DDS_OrgOrderList" 
                                      AutoLoad="False" 
                                      QueryName="GetOrganizationListByIDQuery" 
                                      LoadedData="DDS_OrgOrderList_LoadedData"
            <riaControls:DomainDataSource.DomainContext> 
                <localWeb:MessageContext/> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.QueryParameters> 
                <riaData:Parameter ParameterName="orgID"/> 
            </riaControls:DomainDataSource.QueryParameters> 
</riaControls:DomainDataSource>

<core:HierarchicalDataTemplate x:Key="Org" ItemsSource="{Binding Orgs}">            
<StackPanel Orientation="Horizontal">               
 
<Image Source="{Binding Image}" Margin=" 0,0,6,0" />                
<TextBlock Text="{Binding ID}"  Margin=" 0,0,6,0" FontSize="12" />               
 
<TextBlock Text="{Binding Name}" FontSize="12" />            
</StackPanel>      
 
</core:HierarchicalDataTemplate>








<telerikNavigation:RadTreeView SelectionMode="Extended" IsLineEnabled="True" 
ItemsOptionListType="CheckList"  IsOptionElementsEnabled="True" 
IsRootLinesEnabled="True" SelectionChanged="OrgTree_SelectionChanged" Selected="OrgTree_Selected" 
Checked="OrgTree_Checked" Unchecked="OrgTree_Unchecked"   
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" x:Name="OrgTree" 
IsTriStateMode="True" ItemTemplate="{StaticResource Org}"     
Expanded="OrgTree_Expanded" PreviewExpanded="OrgTree_PreviewExpanded"/> 
        public void DDS_OrgOrderList_LoadedData(object sender, LoadedDataEventArgs e) 
        { 
            var myOrgLists = e.Entities; 
 
            Member m = new Member(); 
             
 
            Org _root; 
            Org _pOrg;  
            Org _cOrg;  
             
            
             
             
            
            m.Add(_root = new Org(1, "root", 1, 0, "0",null,"")); 
 
            int _level = 0; 
            _pOrg = _root; 
            
            foreach (OrgOrderList anOrg in myOrgLists) 
            { 
 
                if (anOrg.treepath.Length == 1) 
                { 
                    continue
                } 
                else if (anOrg.level != _level)    
                { 
                     
 
                    for (int f = 1; f < (anOrg.treepath.Length - 1) / 8; f++)  
                    { 
 
                        int _index = Int32.Parse(anOrg.treepath.Substring(1 + (f-1) * 8, 8)) - 1; 
                        _pOrg = _pOrg.Orgs[_index]; 
 
                    } 
 
                } 
 
                _level = anOrg.level; 
 
                 
 
                _cOrg = new Org(anOrg.orgID, anOrg.orgName, (int)anOrg.orgTypeID, anOrg.level, anOrg.treepath,anOrg.personID,anOrg.pName); 
                _pOrg.Orgs.Add(_cOrg); 
 
                 
                 
            } 
            
            OrgTree.ItemsSource = m; 
 
 
           
 
             
        } 

4 Answers, 1 is accepted

Sort by
0
Eric Zeng
Top achievements
Rank 1
answered on 29 Mar 2010, 06:36 AM

Additional remarks:
Now, I need to foreach my treeview:"OrgTree", but I don't know how to transform the node(type:Org;;
HomePage.Title x in TeamTree.Items{}
) to the type of RadTreeViewItem (because only do this,I can set CheckState for node).
0
Tina Stancheva
Telerik team
answered on 30 Mar 2010, 02:57 PM
Hi Eric Zeng,

In your case I' suggest you use ContainerBinding. Basically it binds a property of the container (RadTreeViewItem in this case) to a property from the business model, like this:

<telerik:ContainerBindingCollection x:Name="BindingsCollection">
            <telerik:ContainerBinding PropertyName="CheckState" Binding="{Binding IsSelected,
               Mode=TwoWay, Converter={StaticResource CheckStateConverter}}"/>

</telerik:ContainerBindingCollection>


More information on how to use ContainerBindings to set the CheckState property of the RadTreeViewItems, you can find here.

However, if your scenario requires you to search through the ItemsSource collection of the RadTreeView,  what you can do, after you find an item that has to be checked, is the following:
path = anOrg.ToString();
RadTreeViewItem
targetItem = treeView.GetItemByPath(path);

targetItem.CheckState = System.Windows.Automation.ToggleState.On;

You can also take a look at the project I attached. It illustrates how to set the CheckState property of the RadTreeViewItems using ContainerBindings. It also demonstrates how to search through the ItemsSource collection of a RadTreeView and highlight and expand the items that match the search criteria.

Please let me know if you need more info or if your scenario requires a different approach.

All the best,
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.
0
Loring Vogel
Top achievements
Rank 1
answered on 15 May 2010, 01:10 AM
does this method support isVirtualizing=true?

if not how can i bind the checkbox in a treeview with my data?
0
Tina Stancheva
Telerik team
answered on 19 May 2010, 05:06 PM
Hi Loring Vogel,

Yes, you can use ContainerBinding to configure which TreeViewItems to be checked in a RadTreeView with an IsVirtualizing  property set to True.

Please let us know if you have any issues with it or if you need more info.

All the best,
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
Eric Zeng
Top achievements
Rank 1
Answers by
Eric Zeng
Top achievements
Rank 1
Tina Stancheva
Telerik team
Loring Vogel
Top achievements
Rank 1
Share this question
or