|
 |
|
|
Hello! When i additing the TriStateTreeView control on a form an error: Failed to create component... Could not find any resources appropriate for the specified culture or the neutral culture... What is the problem???
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I had a number of problems with the TriStateTreeView class in VB on this site, but would you believe it, it is possible to simply add the .cs file from this project, and add references to the two dll's, and it works perfectly as a valid VB class.
Damn if that isn't outstanding.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Great Control!
I am using CheckBoxes = true. I notice that when you change Theme in Windows from Windows XP to Windows classic or reverse the TreeView does not Update, you has to restart the application. Anyone know how to fix this or how to work around it?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I added the TriStateTreeView control on my form, but a check box isn't displayed near the name of the node. I can see that there is some free place where the boxes should appear, but they don't appear, like the images of the boxes can't be loaded. And when i click on them the AfterCheck event is fired.
What am i don't wrrong. I added the 2 dlls as references in my project, and also the .cs file. I can use the control but the checkboxes don't appear 
Anybody having the same problem?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Is it possible with the code to call the OnBeforeCeck(e) method instead?
or, what I really want to do is to be able to know whent the TreeView has updated all nodes, so I can Save the states of the nodes and be able to copy them to another TreeView. Any suggestions?
-- modified at 4:32 Friday 20th July, 2007
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
hi I have a problem where I have to add 3 images on same tree node. these images have to be placed side by side.. Is there some way i can do it.. Thanks in advance..
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi...
I test in a Windows Application and works fine...
But in a Smart Device Application (Pocket PC 2003) the component are desactevated in Toolbox...
How I use this control in A Smart Device Application?
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi!
Im making a Database access program and like this tri-state method for sorting the tables. Im getting this to sort the tables as thay should, how ever. When I try to call what boxes are checked there is no output. from the ArrayList. Right now I have a peace of code that is run when Connect/Refresh button is pushed. It looks like this.
public void scThreeCheckedChoises() { ArrayList ChkList = new ArrayList(); ChkList = dcTriStateTreeView2.GetCheckedTagData();
string test = System.String.Concat(ChkList.ToArray()); string ChkStr = "";
foreach (string s in ChkList) { ChkStr = s; } MessageBox.Show(ChkStr); MessageBox.Show(test); }
I want it to a singel string row as it should talk to the SQL server what tables to select. I get nothing out at all, shouldnt I use .GetCheckedData to retrive the checked alternativs in treeview? Would be grate If anyone could help.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I tried to do a count command on the ArrayList but it replays "0" no matter how it is checked.
ArrayList ChkList = new ArrayList(); ChkList = triStateTreeView1.GetCheckedTagData();
MessageBox.Show(ChkList.Count.ToString());
Seems like there is a problem with the code that should count the checked alternatives. Or?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I Solved the problem. re wrote some code.
public ArrayList CountTheChecked = new ArrayList();
private void BuildTagDataList(TreeNode node, ArrayList list) { foreach (TreeNode child in node.Nodes) { if (GetChecked(child) == CheckState.Checked && child.Text != "") { CountTheChecked.Add(child.Text); } } }
This can then be calld and will return the checked children.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You can also check what the imageindex is set to. 1 is OFF, 2 is ON, and I assume that 3 is indeterminite.
bNowActive = (tnNode.ImageIndex = 2)
if (bNowActive = true) then ' do the stuff for the checked item else ' do the stuff for the unchecked item end if
At least that's what I did when using this in VB.Net. It should be the same here.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Images are mirrored in the Right-To-Left Layout ?! Advice ...
Ahmed Amin El-Morali S/W Developer EGYPT
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hello
I used a more simple code to mimics a three-state treeview. I use the StateImageList property instead. See the code below:
using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles;
namespace Sample { public class ThreeStateTreeView : TreeView { private const int STATE_UNCHECKED = 0; //unchecked state private const int STATE_CHECKED = 1; //checked state private const int STATE_MIXED = 2; //mixed state (indeterminate) private ImageList _InternalStateImageList; //state image list
//create a new ThreeStateTreeView public ThreeStateTreeView() : base() { }
//initialize all nodes state image public void InitializeNodesState(TreeNodeCollection nodes) { foreach (TreeNode node in nodes) { node.StateImageIndex = 0; if (node.Nodes.Count != 0) { InitializeNodesState(node.Nodes); } } }
//update children state image with the parent value public void UpdateChildren(TreeNode parent) { int state = parent.StateImageIndex; foreach (TreeNode node in parent.Nodes) { node.StateImageIndex = state; if (node.Nodes.Count != 0) { UpdateChildren(node); } } }
//update parent state image base on the children state public void UpdateParent(TreeNode child) { TreeNode parent = child.Parent;
if (parent == null) { return; }
if (child.StateImageIndex == STATE_MIXED) { parent.StateImageIndex = STATE_MIXED; } else if (IsChildrenChecked(parent)) { parent.StateImageIndex = STATE_CHECKED; } else if (IsChildrenUnchecked(parent)) { parent.StateImageIndex = STATE_UNCHECKED; } else { parent.StateImageIndex = STATE_MIXED; } UpdateParent(parent); }
//returns a value indicating if all children are checked public static bool IsChildrenChecked(TreeNode parent) { return IsAllChildrenSame(parent, STATE_CHECKED); }
//returns a value indicating if all children are unchecked public static bool IsChildrenUnchecked(TreeNode parent) { return IsAllChildrenSame(parent, STATE_UNCHECKED); }
//returns a value indicating if all children are in the same state public static bool IsAllChildrenSame(TreeNode parent, int state) { foreach (TreeNode node in parent.Nodes) { if (node.StateImageIndex != state) { return false; } if (node.Nodes.Count != 0 && !IsAllChildrenSame(node, state)) { return false; }
} return true; }
//build the checked, unchecked and indeterminate images private static Image GetStateImage(CheckBoxState state, Size imageSize) { Bitmap bmp = new Bitmap(16, 16); using (Graphics g = Graphics.FromImage(bmp)) { Point pt = new Point((16 - imageSize.Width) / 2, (16 - imageSize.Height) / 2); CheckBoxRenderer.DrawCheckBox(g, pt, state); } return bmp; }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (_InternalStateImageList == null) { _InternalStateImageList = new ImageList(); using (Graphics g = base.CreateGraphics()) { Size glyphSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.UncheckedNormal, glyphSize)); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.CheckedNormal, glyphSize)); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.MixedNormal, glyphSize)); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.UncheckedDisabled, glyphSize)); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.CheckedDisabled, glyphSize)); _InternalStateImageList.Images.Add(GetStateImage(CheckBoxState.MixedDisabled, glyphSize)); } } base.StateImageList = _InternalStateImageList;
InitializeNodesState(base.Nodes); }
//check if user click on the state image protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); if (e.Button == MouseButtons.Left) { TreeViewHitTestInfo info = base.HitTest(e.Location); if (info.Node != null && info.Location == TreeViewHitTestLocations.StateImage) { TreeNode node = info.Node; switch (node.StateImageIndex) { case STATE_UNCHECKED: case STATE_MIXED: node.StateImageIndex = STATE_CHECKED; break; case STATE_CHECKED: node.StateImageIndex = STATE_UNCHECKED; break; } UpdateChildren(node); UpdateParent(node); } } }
//check if user press the space key protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.KeyCode == Keys.Space) { if (base.SelectedNode != null) { TreeNode node = base.SelectedNode; switch (node.StateImageIndex) { case STATE_UNCHECKED: case STATE_MIXED: node.StateImageIndex = STATE_CHECKED; break; case STATE_CHECKED: node.StateImageIndex = STATE_UNCHECKED; break; } UpdateChildren(node); UpdateParent(node); } } }
//swap between enabled and disabled images protected override void OnEnabledChanged(EventArgs e) { base.OnEnabledChanged(e);
for (int i = 0; i < 3; i++) { Image img = _InternalStateImageList.Images[0]; _InternalStateImageList.Images.RemoveAt(0); _InternalStateImageList.Images.Add(img);
} } } }
|
| Sign In·View Thread·PermaLink | 4.37/5 (8 votes) |
|
|
|
 |
|
|
Excellent! This is by far the most simple and straight forward implementation of a three state checkboxed tree view control with themed checkboxes.
|
| Sign In·View Thread·PermaLink | 1.80/5 (4 votes) |
|
|
|
 |
|
|
 |
|
|
hi laurent,
do you have a working sample for me? I'm not the best in c# programming, but I like this tristate treeview!
hamlet
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Try this with your code:
TreeNode tn; public Form1() { InitializeComponent();
tn = threeStateTreeView1.Nodes.Add("test"); tn.Nodes.Add("1"); tn.Nodes.Add("2"); tn.Nodes.Add("3");
tn = threeStateTreeView1.Nodes.Add("Wow"); tn.Nodes.Add("10"); tn.Nodes.Add("20"); tn.Nodes.Add("30");
}
private void button1_Click(object sender, EventArgs e) { tn.Checked = true; }
All of the children do not get checked
wahoo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello,
You must not set the checked property but the StateImageIndex property. After that You call UpdateChildren(TreeNode) and UpdateParent(Tree node)
For example:
private void button1_Click(object sender, EventArgs e) { tn.StateImageIndex = 1; //1 for checked, 0 for unchecked threeStateTreeView1.UpdateChildren(tn); threeStateTreeView1.UpdateParent(tn); }
That's all.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Careful, the control behaves like the TreeView control when his Cheboxes property is set to True in the designer under Visual Studio 2005.
By the way having the Checkboxes property unset means that AfterCheck and beforecheck events won't work anymore. That is placing some raiseevent statements at the appropriate places should correct this issue.
|
| Sign In·View Thread·PermaLink | 4.00/5 (1 vote) |
|
|
|
 |
|
|
Very nice, thanks!
But instead of using OnMouseClick, you should use OnNodeMouseClick. Clicking on the +/- image will also fire OnMouseClick and the hit-test is done after the TreeView expands or collapses. This can cause the hit-test to be incorrect if the TreeView scrolls during the expand/collapse and can change the state of items inadvertently. OnNodeMouseClick does not fire if the clicked node position changes as a result of a scroll.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You can use StateImageList to display checkboxes, so you could use ImageList to display some images.
I wrote also some code you can find useful.
void treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { // determine if there is a checkbox if (e.Node.StateImageIndex >= 0) { int offset = 3 + (e.Node.TreeView.ImageList == null ? 0 : e.Node.TreeView.ImageList.ImageSize.Width); // determine if checkbox was clicked if (e.X >= e.Node.Bounds.Left - (offset + e.Node.TreeView.StateImageList.ImageSize.Width) && e.X < e.Node.Bounds.Left - offset) { bool? state = e.Node.StateImageIndex == 0 ? false : (e.Node.StateImageIndex == 1 ? (bool?)true : null); // state: false = unchecked, true = checked, null = undetermined ////// // BeforeCheck event here ////// // do something with state ////// e.Node.StateImageIndex = state.HasValue ? (state.Value ? 1 : 0) : 2; ////// // AfterCheck event here ////// } } }
Regards, Łukasz Świątkowski
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |