Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a TreeView Check box to partially checked?

I have a asp.net treeview control that I need to be able to set a parent node to partially checked to show that child nodes are checked. Basically I need a 3 state or multi-state checkbox. All I can see from looking through the code is ways to set checked true or false.

Thanks.

like image 527
Dilbert789 Avatar asked Feb 18 '10 18:02

Dilbert789


2 Answers

There is no 3-state or multi-state checkbox in the .Net framework, mostly because this functionality isn't supported in HTML for a checkbox. There are a number of third party components which do this (such as "FolderView" controls). Or you could pretty easily roll your own server control for this. Sorry for the bad news.

like image 61
Tim C Avatar answered Oct 18 '22 03:10

Tim C


I've done this before. What you essentially do is keep track of the state of the underlying checkbox. Utilizing a custom javascript class and CSS sprites for your images, you overlay the checkbox with the appropriate image.

Here is a quick example I found

http://www.codeproject.com/KB/aspnet/TriStateCheckBox.aspx

Here is the concept of CSS Sprites and the tri-state checkbox. I've done something along these lines.

http://shamsmi.blogspot.com/2008/12/tri-state-checkbox-using-javascript.html

like image 26
Danny G Avatar answered Oct 18 '22 01:10

Danny G