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

Can I display checkboxes for specific items?

2 Answers 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
fred williams
Top achievements
Rank 1
fred williams asked on 19 Apr 2011, 05:04 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 22 Apr 2011, 08:57 AM
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
0
fred williams
Top achievements
Rank 1
answered on 22 Apr 2011, 09:58 AM
Perfect, thanks!
Tags
TreeView
Asked by
fred williams
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
fred williams
Top achievements
Rank 1
Share this question
or