Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# Treeview with (partial) CheckBoxes

Started by PhilHalf Sep 19, 2006 at 2:57 PM 0 replies 2.7k views
Original Post
PhilHalf
PhilHalf
Hi all, I'm looking at creating a program (in C#) that basically lists the subdirectories of a specified root directory. When the subdirectory contains one or more files that meet a certain criteria (e.g. are *.bat files), you can choose that the file will be run (you can only run one file from a subdirectory, using radio button selection). That bit's not a problem. What I'd like to do is put a checkbox next to the directories that contain the files so that you can tick the ones that you'd want to run. I could set the CheckBoxes property of the treeview, but that would display next to every node and I'd only want to give the option of ticking the directories with the relavant fies in them. For example, say I have the following folder/file structure:

C:
  Directory1
    SubDirectory1
      File1.bat
    SubDirectory2
  Directory2
    File3.bat
(Note: the files would not be displayed in the treeview, they would show up in a seperate control when the directory is selected). I'd only want checkboxes next to SubDirectory1 and Directory2. Is this a simple property that I'm missing or would I need to write a custom control to do this? I'm not sure I explained that very well... Thanks in advance for any help or advice, PhilHalf
Simagery
Simagery
Unfortunately, MS didn't expose this functionality in the C# TreeView for some reason (it may be in Framework 2.0, but I don't think so). Who knows why... it's incredibly common and useful (and trivial to implement).

Fortunately, lots of people have tackled this. Don't rewrite it, find one over at CodeProject or a similar site. A quick search found me this one:

http://www.codeproject.com/cs/miscctrl/TriStateTreeViewSubmissio.asp

This may be the one I used in the past... regardless, I definitely used one off that site (an excellent C# resource) and it works fine.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.