Can I display checkboxes for specific items?

3 posts, 1 answers
  1. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 19 Apr 2011 Link to this post

    I'm creating a windows explorer interface and I'd like to display checkboxes for files and not directories. If I set isOptionElementsEnabled to true it shows checkboxes next to them all. I tried setting isOptionElementsEnabled to true and then programmatically disabling the checkboxes for directories this way:

                DirectoryInfo di = new DirectoryInfo(_currentPath);
                DirectoryInfo[] directories = di.GetDirectories();
                FileInfo[] files = di.GetFiles();           
     
    foreach (DirectoryInfo dInfo in directories)
                {
                    RadTreeViewItem tvDirectoryItem = new RadTreeViewItem() { Header = dInfo.Name, DefaultImageSrc = "folder_icon.gif"};
                    tvDirectoryItem.ItemsOptionListType = OptionListType.None;
                    tvDirectory.Items.Add(tvDirectoryItem);
                }
                foreach (FileInfo fInfo in files)
                {
                    //tvDirectory.IsOptionElementsEnabled = true;
                    RadTreeViewItem tvFileItem = new RadTreeViewItem() { Header = fInfo.Name };
                    tvFileItem.ItemsOptionListType = OptionListType.CheckList;
                    tvDirectory.Items.Add(tvFileItem);
                }


    but it didn't work. Is there anyway to do this outside of using two separate treeviews on top of each other?
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Apr 2011 Link to this post

    Hi fred williams,

    You can use the OptionType property  of the RadtreeViewItem. It applies only to the Item but the ItemsOptionListType applies to all SubItems. Let us kno if this helps you.
    private void PopulateTree()
           {
               for (int i = 0; i < 3; i++)
               {
                    RadTreeViewItem tvDirectoryItem = new RadTreeViewItem() { Header = "Dir" + i, 
                        ItemsOptionListType = OptionListType.OptionList, 
                        OptionType= OptionListType.None };
                    for (int j = 0; j < 2; j++)
                    {
                         RadTreeViewItem sub = new RadTreeViewItem() { Header = "SubDir" + i};
                         tvDirectoryItem.Items.Add(sub);
                    }
                    this.treeView.Items.Add(tvDirectoryItem);
               }
               for (int i = 0; i < 4; i++)
               {
                   RadTreeViewItem tvFileItem = new RadTreeViewItem() { Header = "file" + i, ItemsOptionListType = OptionListType.CheckList,
                   OptionType=OptionListType.CheckList};
                   for (int k = 0; k < 2; k++)
                   {
                       RadTreeViewItem sub = new RadTreeViewItem() { Header = "SubFile" + i};
                         tvFileItem.Items.Add(sub);
                   }
                   this.treeView.Items.Add(tvFileItem);
               }              
           }


    Kind regards,
    Petar Mladenov
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. fred williams
    fred williams avatar
    55 posts
    Member since:
    Feb 2010

    Posted 22 Apr 2011 Link to this post

    Perfect, thanks!
Back to Top