|
you can solve Issue 2:
"by clicking on the new checkbox you only cycle between checked/unchecked, third state can only be changed programmaticaly"
with another OnAfterCheck:
protected override void OnAfterCheck(TreeViewEventArgs e) {
base.OnAfterCheck(e);
ThreeStateTreeNode node = e.Node as ThreeStateTreeNode;
if(node == null) return;
node.ThreeStateChecked = (ThreeState)(((int)(node.ThreeStateChecked) + 1) % 3);
}
please add a second level to the treeview of the demo:
public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
foreach(var item in System.IO.Directory.GetDirectories("c:\\")) {
var nd = new TreeViewThreeState.ThreeStateTreeNode(item);
_threeState.Nodes.Add(nd);
try {
foreach(var item2 in System.IO.Directory.GetDirectories(nd.FullPath)) {
nd.Nodes.Add(new TreeViewThreeState.ThreeStateTreeNode(item2));
}
} catch(UnauthorizedAccessException) { }
}
}
}
|
|
|
|
|
Thank you, I will update the project when I have some more time.
|
|
|
|
|
Dalibor Carapic wrote: Thank you, I will update the project when I have some more time.
Don't hurry, be happy!
|
|
|
|
|
Hi!
i found out, that i can set the third state by user, namely by doubleclicking a checkbox.
But i have no idea, how that works.
When i did so (set the state.indeterminated by doubleclick) the form is in a special state. E.G. you cannot close it anymore by Alt-F4.
The form seem to loose the focus, but where is it gone (the focus)?
cheers
|
|
|
|
|
How this ended up in Advanced i dont understand...
With great code, comes great complexity, so keep it simple stupid...
|
|
|
|
|
I do not understand your comment. I am not providing a production ready complete control for someone to use (I would charge for it then). I rather share information/code that was useful for me. If you can find use in it then good for you, if not, well at least you have a bit more knowledge
|
|
|
|
|
|
|
... sigh, I guess that there are trolls everywhere ...
|
|
|
|
|
|
sorry, IMO the use of the NativeMethods, as it's shown in the codefiles, is advanced, definitly.
|
|
|
|
|
Your control no works, it does not display three states. You should make a test project and upload it.
|
|
|
|
|
I've updated the source files, I've added a small test project. As noted in the article, the third state (indeterminate) can only be set programmaticaly.
|
|
|
|
|
"Hello Please may I introduce myself. My name is Zin Mar.There is no problem in downloading source code but I do not run source code. It gives me message "A project with a output type of class library cannot be started directly. In order to debug this project ,add an executable project to this source which references the library project.Set the executable project as the startup project." I am beginner of C# language. So, I cannot resolve this problen. let me know solution. Thanks for your help"
- Zin Mar
|
|
|
|
|
Hi,
The solution only contains the project with the control itself. There is no sample on how to use it. The easiest way to test it is to add a new project to the solution (C# Windows Forms project) and then place the control on the default form that will be added to the new project (the control should appear in the toolbox automaticaly).
|
|
|
|
|
Maybe a dumb question but is there a way that this control will manage checking / unchecking of child nodes depending on the state of the parent node?
How can this be done?
Also, is there some way to show a 3rd image state? For example, if a parent node has 3 children with 2 of them checked, can the parent show a different image other that checked or empty?
Again, how can this be done???
|
|
|
|
|
In other words - to get the behavior shown in the sample form above! Maybe if the source for the sample test form was provided that might help.
Thanks,
|
|
|
|
|
lessms wrote: In other words - to get the behavior shown in the sample form above! Maybe if the source for the sample test form was provided that might help.
Thanks,
Hi,
If I understand you correctly you would like to change the state of the parent node when a child node changes so that you get
- not-checked when none of the children are checked
- checked when all of the children are checked
- intermediate (gray) state whenever some children are not checked
This seems like the most common use of tri-state Tree control.
The control does not support this and you would have to do this manually, either externally by hooking up to AfterThreeStateCheck event provided by the control or by modifying the control and adding the functionality inside.
As for how to do it, the easiest would be the following:
- check when the user clicks on any node
- check/uncheck all the children of that node depending on the new state
- calculate the parent node state by going through all parents and taking a look if all children are checked/unchecked/indeterminate
Hope I helped.
|
|
|
|
|
Thanks, but when you say "The control does not support this" YET the picture at the top of the article is showing this control (supposedly) doing this, I have to wonder what this control is even good for.
Wouldn't it make sense to offer a tri-state tree control where the control performed the tri-state logic?
I think this article is incorrectly (deceptively) named.
|
|
|
|
|
Hi,
The picture above is possible (after all it is a screenshot) if you set the third state of a checkbox in the code. If you want you can extend the provided control to add whatever functionality you require. You could add code to make the third state appear if you double-click on checkbox or to cycle through states by clicking on the checkbox. The essence of the article is to provide a demonstration on how a tri-state tree control can be made in a simple way (by extending the existing control).
It is by no means a production-ready control and would require more work for some of the things that you mentioned.
However if you want to add the functionality that I described in the previous post (setting the child nodes by clicking on the parent node checkbox and setting the state of a node checkbox when the children nodes are set/unset) then the control should suit your needs because the said functionality should be relatively simple to implement. BTW this is the primary reason that I needed to control in the first place.
I have also stated in the 'Issues' part of the article what are the issues in using the control.
Hope this helps.
|
|
|
|
|
Ah, you are correct - I should have read the limitations better.
I did find a different Tri-state TreeView on CodeProject that is functional (by Ebse).
I would still like to thank you for posting your project and also thank you for your very prompt replies!
|
|
|
|
|
Hi,
No problem, I hope that you will find what you are looking for.
|
|
|
|
|
To make this control theme aware on windows XP we can make use of the Adding XP Themes to Custom .NET Controls submission from Don Kackman. By referening his Themes code we can initialise the tree view image list like this and benefit from themed check marks.
public ThreeStateThreeView()
{
base.CheckBoxes = true;
_imageList = new ImageList();
_imageList.ImageSize = new Size(16, 16);
if (UxTheme.IsAppThemed)
{
ThemePart checkboxThemes = new ThemeInfo()["BUTTON"].Parts["CHECKBOX"];
_imageList.Images.Add(Properties.Resources.Checked0, Color.White);
SetThemedCheckboxImage(checkboxThemes, "UNCHECKEDNORMAL");
SetThemedCheckboxImage(checkboxThemes, "CHECKEDNORMAL");
SetThemedCheckboxImage(checkboxThemes, "MIXEDNORMAL");
}
else
{
_imageList.Images.Add(Properties.Resources.Checked0, Color.White);
_imageList.Images.Add(Properties.Resources.Checked1, Color.White);
_imageList.Images.Add(Properties.Resources.Checked2, Color.White);
_imageList.Images.Add(Properties.Resources.Checked3, Color.White);
}
}
private void SetThemedCheckboxImage(ThemePart checkboxThemes, String stateName)
{
Rectangle r = new Rectangle(0, 0, 16, 16);
Bitmap bmp;
Graphics g;
bmp = new Bitmap(16, 16);
g = Graphics.FromImage(bmp);
checkboxThemes.States[stateName].DrawBackground(g, r);
_imageList.Images.Add(bmp);
}
|
|
|
|
|
Hi
I am an ASP.NET beginner and want to create a web site for training.
I want to have a three state treeview for my asp.net web site.
I found this article, and then I add this project (the TreeViewThreeState project) to my web site solution.
In the page that I want to have a treeview I add this lines
<%@ Import Namespace="ThreeStateThreeView" %>
<%@ Register TagPrefix=" ThreeStateThreeView" Namespace="ThreeStateThreeView" Assembly="TreeViewThreeState " %>
And I recive this error that
Parser Error Message: Could not load file or assembly 'TreeViewThreeState' or one of its dependencies. The system cannot find the file specified
If I did not add these lines to my code I receive this error that <treeviewthreestate> is not a known element.
Also I have these errors:
At file “ThreeStateThreeView.cs” line 160 I receive these errors
The type or namespace name 'SerializationInfo' could not be found (are you missing a using directive or an assembly reference?)
And
The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?)
public ThreeStateTreeNode(SerializationInfo serializationInfo, StreamingContext context)
I change that line to
public ThreeStateTreeNode(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context)
Now I recive this errors at file “ThreeStateThreeView.cs” lines “28-31” I receive this error:
The name 'Resource' does not exist in the current context
Now first I want to know for use this treeview what can I do? Must I compile the ThreeStateThreeView project to a “.dll” assembly file and add it to bin folder or must add ThreeStateThreeView project to my solution or...?
Then I want to know how solve those problems?
At the end I want my treeview will be full from a table of database and at the page close save all checked and unchecked and other type to database, is it possible with this control?
Please help me.
Thanks a lot.
|
|
|
|
|
Hi Mohsen,
You can't use Windows Forms components in a asp.net application. System.Web code can't use System.Windows.Forms controls.
myMsg.BehindDaKeys = "Chris Richner";
|
|
|
|