|
Thanks......
|
|
|
|
|
|
hi,
i used this and developed one form and it is working nice. But when i deploy in other system form not showing any tree view control. Kindly help as soon as possible. I added 2 ddl to the application path
|
|
|
|
|
This works very well, especially with those changes for the x64 machines.
One thing though, how do you hide some of the checkboxes? I found this article here who's answer will work perfectly with a regular TreeView, but I'm thinking that there is something in your API overrides that is keeping this other code from working.
Any help would be greatly appreciated.
|
|
|
|
|
gracias era lo que estaba buscando
|
|
|
|
|
Hello there, I found this control perfect for me, from many check tree ininternet this is the perfect one, but still I have 1 problem:
My application is a Right To Left application and I need this Tree to be RightToLeft too, I think the tric is in function Draw, but we don't have its code, is there any way to solve this prob???
Thanks in advance
|
|
|
|
|
I think it should work if you set the RightToLeft and RightToLeftLayout properties:
this.triStateTreeView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.triStateTreeView1.RightToLeftLayout = true;
|
|
|
|
|
It's the only one decision that works well. With some minor changes it helped me to do my job!
|
|
|
|
|
I use a subroutine to fill the treeview by looping through parent and child records in a SQLite database. It works fine when the db is opened during form_load but if the db is built after the form loads, the tableadapters are filled and then the same subroutine is run, the treeview scroll bars are visible but the nodes are not. I have stepped through the code in debug mode and know that tvRooms.Nodes.Count > 0 and the subroutine does not terminate early. Has anyone else seen this behavior and, if so, what can I do to fix it? Here is the subroutine:
Private Sub FillTreeView()
Try
With tvRooms
.BeginUpdate()
.Nodes.Clear()
For Each drRoom As DataRow In HouseholdInventoryDataSet.Tables("Rooms").Rows
'Adds the room as a root node
Dim nodParent As TreeNode
nodParent = tvRooms.Nodes.Add(drRoom.Item("Room").ToString)
nodParent.Tag = drRoom.Item("Room").ToString
For Each drItem As DataRow In drRoom.GetChildRows(HouseholdInventoryDataSet.Relations("Rooms_Inventory"))
'Adds the inventory item as child of the room
Dim nodChild As TreeNode
nodChild = nodParent.Nodes.Add(drItem.Item("ItemName").ToString)
nodChild.Tag = drItem.Item("ID")
Next drItem
Next drRoom
If tvRooms.Nodes.Count = 0 Then Exit Sub
.ExpandAll()
.Nodes(0).EnsureVisible()
.EndUpdate()
End With
Catch ex As Exception
gMsg = "The following error occurred filling the tree view: " + vbCrLf + ex.Message
MsgBox(gMsg)
End Try
End Sub
|
|
|
|
|
Solved. I changed
If tvRooms.Nodes.Count = 0 Then Exit Sub
.ExpandAll()
.Nodes(0).EnsureVisible()
.EndUpdate()
to
If tvRooms.Nodes.Count = 0 Then
.EndUpdate()
Exit Sub
Else
.ExpandAll()
.Nodes(0).EnsureVisible()
.EndUpdate()
End If
I don't know why this worked and the other did not. Apparently the control did not register the .EndUpdate() in the first method.
|
|
|
|
|
Hi,
I tried this dll with my application and application can use this dll in my local mechine(WIndows XP).Then i had deployed the application on 64 bit windows server i got the error message application has stopped working.
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: tristate.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4c917bd9
Problem Signature 04: tristate
Problem Signature 05: 1.0.0.0
Problem Signature 06: 4c917bd9
Problem Signature 07: 9
Problem Signature 08: 11
Problem Signature 09: System.BadImageFormatException
OS Version: 6.0.6002.2.2.0.274.10
Locale ID: 1033
Can you please advice how i can solve this issue
Regards,
Sajesh
|
|
|
|
|
Hello Sajesh,
I have found how to make it work in x64. Open the source code, and make the following changes in the constructor.
public TriStateTreeView()
{
InitializeComponent();
if (ThemeInformation.VisualStylesEnabled)
{
Bitmap bmp = new Bitmap(m_TriStateImages.ImageSize.Width, m_TriStateImages.ImageSize.Height);
Rectangle rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
Graphics graphics = Graphics.FromImage(bmp);
ThemePaint.Draw(graphics, this, ThemeClasses.Button, ThemeParts.ButtonCheckBox, ThemeStates.CheckBoxCheckedDisabled, rc, rc);
m_TriStateImages.Images[0] = bmp;
ThemePaint.Draw(graphics, this, ThemeClasses.Button, ThemeParts.ButtonCheckBox, ThemeStates.CheckBoxUncheckedNormal, rc, rc);
m_TriStateImages.Images[1] = bmp;
ThemePaint.Draw(graphics, this, ThemeClasses.Button, ThemeParts.ButtonCheckBox, ThemeStates.CheckBoxCheckedNormal, rc, rc);
m_TriStateImages.Images[2] = bmp;
}
ImageList = m_TriStateImages;
ImageIndex = (int)CheckState.Unchecked;
SelectedImageIndex = (int)CheckState.Unchecked;
}
You can dereference the Skybound.visualstyles.dll. That's all I did to use the control in x64 machines. Hope this helps.
Regards,
Cody
|
|
|
|
|
It Does not work on win7 64x?!?!
could you upload a sample on win 64x
|
|
|
|
|
Hello,
If you get the bad image format exception, I think you need to open the source code, remove the reference to SkyVisualBound.dll (follow what I mentioned previously) and build it in "Any CPU".
Regards,
Cody Tang
|
|
|
|
|
|
Hi,
I'm trying to use this control in a VS 2008 project. I'm able to compile it fine and add it to a test form but when I try to run the application I get a BadImageFormatException. Is there a problem with how I am building the dll or something like that? Has anyone else had this problem and resolved it?
I'd appreciate any help I can get,
Devonmodified on Wednesday, February 17, 2010 7:00 PM
|
|
|
|
|
I've discovered a little more. If I change the build options from Any CPU to x86 then it works. Unfortunately the project I want to integrate this in must build for Any CPU.
Any suggestions?
Devon
|
|
|
|
|
As noted in a previous message, I found this control extremely useful, so thx a bunch for that.
One thing I was missing, however, was the ability to enable and disable specific tree nodes. Adding an Enabled property to a derived class of the TreeNode would have been too complex because I'd have to inherit from several other classes as well and it would get messy.
Instead, I added a DisabledColor property to your TriStateTreeView. Set this property to a particular color (such as SystemColors.GrayText), and then whenever you need to disable a node, set its ForeColor to this color as well. The TriStateTreeView will then properly manage the click states of all parent and child nodes accordingly.
I can't find a way to put an attachment here, so I'm forced to paste the class.
Hope it comes in handy to someone.
[Note: the CodeProject is truncating the pasted code, as I've probably hit a maximum length or something. See my response to this note with the rest of the code.]
#region // Copyright (c) 2004-2005, SIL International. All Rights Reserved. <br />
#endregion<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Data;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
using System.Runtime.Serialization;<br />
<br />
namespace WinControls<br />
{<br />
public class TriStateTreeView : TreeView<br />
{<br />
private System.Drawing.Color mDisabledNodeColor;<br />
<br />
public System.Drawing.Color DisabledNodeColor<br />
{<br />
get { return mDisabledNodeColor; }<br />
set { mDisabledNodeColor = value; }<br />
}<br />
<br />
private System.Windows.Forms.ImageList m_TriStateImages;<br />
private System.ComponentModel.IContainer components;<br />
public enum CheckState<br />
{<br />
GreyChecked = 0,<br />
Unchecked = 1,<br />
Checked = 2,<br />
}<br />
<br />
#region Redefined Win-API structs and methods<br />
[StructLayout(LayoutKind.Sequential, Pack=1)]<br />
public struct TV_HITTESTINFO<br />
{<br />
public Point pt;<br />
public TVHit flags;<br />
public IntPtr hItem;<br />
}<br />
<br />
[Flags]<br />
public enum TVHit<br />
{<br />
NoWhere = 0x0001,<br />
OnItemIcon = 0x0002,<br />
OnItemLabel = 0x0004,<br />
OnItemIndent = 0x0008,<br />
OnItemButton = 0x0010,<br />
OnItemRight = 0x0020,<br />
OnItemStateIcon = 0x0040,<br />
OnItem = (OnItemIcon | OnItemLabel | OnItemStateIcon),<br />
Above = 0x0100,<br />
Below = 0x0200,<br />
ToRight = 0x0400,<br />
ToLeft = 0x0800<br />
}<br />
<br />
public enum TreeViewMessages<br />
{<br />
TV_FIRST = 0x1100,
TVM_HITTEST = (TV_FIRST + 17),<br />
}<br />
<br />
[DllImport("user32.dll", CharSet=CharSet.Auto)]<br />
public static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TV_HITTESTINFO lParam);<br />
#endregion<br />
<br />
#region Constructor and destructor<br />
public TriStateTreeView()<br />
{<br />
InitializeComponent();<br />
mDisabledNodeColor = SystemColors.GrayText;<br />
ImageList = m_TriStateImages;<br />
ImageIndex = (int)CheckState.Unchecked;<br />
SelectedImageIndex = (int)CheckState.Unchecked;<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if(components != null)<br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
#endregion<br />
<br />
#region Component Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.components = new System.ComponentModel.Container();<br />
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TriStateTreeView));<br />
this.m_TriStateImages = new System.Windows.Forms.ImageList(this.components);<br />
this.m_TriStateImages.ImageSize = new System.Drawing.Size(16, 16);<br />
this.m_TriStateImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_TriStateImages.ImageStream")));<br />
this.m_TriStateImages.TransparentColor = System.Drawing.Color.Magenta;<br />
<br />
}<br />
#endregion<br />
<br />
#region Hide no longer appropriate properties from Designer<br />
[Browsable(false)]<br />
public new bool CheckBoxes<br />
{<br />
get { return base.CheckBoxes; }<br />
set { base.CheckBoxes = value; }<br />
}<br />
<br />
[Browsable(false)]<br />
public new int ImageIndex<br />
{<br />
get { return base.ImageIndex; }<br />
set { base.ImageIndex = value; }<br />
}<br />
<br />
[Browsable(false)]<br />
public new ImageList ImageList<br />
{<br />
get { return base.ImageList; }<br />
set { base.ImageList = value; }<br />
}<br />
<br />
[Browsable(false)]<br />
public new int SelectedImageIndex<br />
{<br />
get { return base.SelectedImageIndex; }<br />
set { base.SelectedImageIndex = value; }<br />
}<br />
#endregion<br />
<br />
#region Overrides<br />
<br />
protected override void OnClick(EventArgs e)<br />
{<br />
base.OnClick (e);<br />
<br />
TV_HITTESTINFO hitTestInfo = new TV_HITTESTINFO();<br />
hitTestInfo.pt = PointToClient(Control.MousePosition);<br />
<br />
SendMessage(Handle, TreeViewMessages.TVM_HITTEST,<br />
0, ref hitTestInfo);<br />
if ((hitTestInfo.flags & TVHit.OnItemIcon) == TVHit.OnItemIcon)<br />
{<br />
TreeNode node = GetNodeAt(hitTestInfo.pt);<br />
if (node != null)<br />
{<br />
ChangeNodeState(node);<br />
}<br />
}<br />
}<br />
<br />
protected override void OnKeyDown(KeyEventArgs e)<br />
{<br />
base.OnKeyDown (e);<br />
<br />
if (e.KeyCode == Keys.Space)<br />
ChangeNodeState(SelectedNode);<br />
}<br />
#endregion<br />
<br />
#region Private methods<br />
private void CheckNode(TreeNode node, CheckState state)<br />
{<br />
bool checkSet = InternalSetChecked(node, state);<br />
<br />
if (checkSet)<br />
{<br />
foreach (TreeNode child in node.Nodes)<br />
{<br />
CheckNode(child, state);<br />
}<br />
}<br />
<br />
ChangeParent(node.Parent);<br />
}<br />
<br />
private void ChangeParent(TreeNode node)<br />
{<br />
if (node == null)<br />
{<br />
return;<br />
}<br />
<br />
CheckState state = GetChecked(node.FirstNode);<br />
foreach (TreeNode child in node.Nodes)<br />
state &= GetChecked(child);<br />
<br />
if (InternalSetChecked(node, state))<br />
{<br />
ChangeParent(node.Parent);<br />
}<br />
}<br />
<br />
protected void ChangeNodeState(TreeNode node)<br />
{<br />
if (node.ForeColor != mDisabledNodeColor)<br />
{<br />
BeginUpdate();<br />
CheckState newState;<br />
if (node.ImageIndex == (int)CheckState.Unchecked || node.ImageIndex < 0)<br />
{<br />
newState = CheckState.Checked;<br />
}<br />
else<br />
{<br />
newState = CheckState.Unchecked;<br />
}<br />
CheckNode(node, newState);<br />
ChangeParent(node.Parent);<br />
EndUpdate();<br />
}<br />
}<br />
<br />
private bool InternalSetChecked(TreeNode node, CheckState state)<br />
{<br />
bool returnValue = true;<br />
if (node.ForeColor != mDisabledNodeColor)<br />
{<br />
TreeViewCancelEventArgs args = new TreeViewCancelEventArgs(node, false, TreeViewAction.Unknown);<br />
OnBeforeCheck(args);<br />
if (args.Cancel)<br />
{<br />
returnValue = false;<br />
}<br />
<br />
node.ImageIndex = (int)state;<br />
node.SelectedImageIndex = (int)state;<br />
<br />
OnAfterCheck(new TreeViewEventArgs(node, TreeViewAction.Unknown));<br />
}<br />
else<br />
{<br />
returnValue = false;<br />
}<br />
return returnValue;<br />
}<br />
<br />
private void BuildTagDataList(TreeNode node, ArrayList list)<br />
{<br />
if (GetChecked(node) == CheckState.Checked && node.Tag != null)<br />
list.Add(node.Tag);<br />
<br />
foreach (TreeNode child in node.Nodes)<br />
BuildTagDataList(child, list);<br />
}<br />
<br />
private void FindAndCheckNode(TreeNode node, object tag, CheckState state)<br />
{<br />
if (node.Tag != null && node.Tag.Equals(tag))<br />
{<br />
SetChecked(node, state);<br />
return;<br />
}<br />
<br />
foreach (TreeNode child in node.Nodes)<br />
FindAndCheckNode(child, tag, state);<br />
}<br />
#endregion<br />
<br />
#region Public methods<br />
public CheckState GetChecked(string nodeName)<br />
{<br />
CheckState returnCheckState = CheckState.GreyChecked;<br />
<br />
TreeNode[] nodes = this.Nodes.Find(nodeName, true);<br />
if (nodes != null && nodes.Length > 0)<br />
{<br />
returnCheckState = GetChecked(nodes[0]);<br />
}<br />
else<br />
{<br />
throw new Exception("Node " + nodeName + " not found.");<br />
}<br />
return returnCheckState;<br />
}<br />
<br />
public CheckState GetChecked(TreeNode node)<br />
{<br />
if (node.ImageIndex < 0)<br />
return CheckState.Unchecked;<br />
else<br />
return (CheckState)node.ImageIndex;<br />
}<br />
<br />
public void SetChecked(TreeNode node, CheckState state)<br />
{<br />
bool stateChanged = InternalSetChecked(node, state);<br />
<br />
if (stateChanged)<br />
{<br />
CheckNode(node, state);<br />
}<br />
ChangeParent(node.Parent);<br />
}<br />
<br />
public void CheckNodeByTag(object tag, CheckState state)<br />
{<br />
if (tag == null)<br />
return;<br />
foreach (TreeNode node in Nodes)<br />
FindAndCheckNode(node, tag, state);<br />
}<br />
<br />
public ArrayList GetCheckedTagData()<br />
{<br />
ArrayList list = new ArrayList();<br />
<br />
foreach (TreeNode node in Nodes)<br />
BuildTagDataList(node, list);<br />
return list;<br />
}<br />
#endregion<br />
}<br />
}<br />
modified on Tuesday, October 13, 2009 12:07 PM
|
|
|
|
|
Thank you for your code Muad'Dubby.
Unfortunatly your past failed, look at the last line of your code :
if (nodes != null && nodes.Length >
seems like something is missing isn't it?
|
|
|
|
|
Yes, sorry about that. I'll post the correct code shortly.
|
|
|
|
|
Looks like all the code is available within my comment, but is not being displayed. Probably a maximum string length was hit or something.
In any case, here is the rest of the code, starting from (and including) the last line which appears truncated in my first note). Sorry about this!
if (nodes != null && nodes.Length > 0)<br />
{<br />
returnCheckState = GetChecked(nodes[0]);<br />
}<br />
else<br />
{<br />
throw new Exception("Node " + nodeName + " not found.");<br />
}<br />
return returnCheckState;<br />
}<br />
<br />
public CheckState GetChecked(TreeNode node)<br />
{<br />
if (node.ImageIndex < 0)<br />
return CheckState.Unchecked;<br />
else<br />
return (CheckState)node.ImageIndex;<br />
}<br />
<br />
public void SetChecked(TreeNode node, CheckState state)<br />
{<br />
bool stateChanged = InternalSetChecked(node, state);<br />
<br />
if (stateChanged)<br />
{<br />
CheckNode(node, state);<br />
}<br />
ChangeParent(node.Parent);<br />
}<br />
<br />
public void CheckNodeByTag(object tag, CheckState state)<br />
{<br />
if (tag == null)<br />
return;<br />
foreach (TreeNode node in Nodes)<br />
FindAndCheckNode(node, tag, state);<br />
}<br />
<br />
public ArrayList GetCheckedTagData()<br />
{<br />
ArrayList list = new ArrayList();<br />
<br />
foreach (TreeNode node in Nodes)<br />
BuildTagDataList(node, list);<br />
return list;<br />
}<br />
#endregion<br />
}<br />
}<br />
|
|
|
|
|
I was looking for something like this for quite some time. You got my 5!
|
|
|
|
|
Hi.. how to verify node in tri-state treeview?
example:
if(mytreeview.Contains(mynode))
{
}
I'm not obtaining to make, always it informs that it does not exist, but it exists the node
help please!
|
|
|
|
|
i've been using this control very successfully for a year or more...thanks ever so much for all your great work!
i'd like to be able to disable certain nodes based on some conditions; can this be done?
my current workaround is to remove the node altogether, but that has its drawbacks. it really would be better to show the node but have it disabled.
thanks
kjward
|
|
|
|
|
Hi
I've had the same issue, and got around it by trapping the BeforeCheck event and testing the node that generated the event. If it's the one I want "disabled" I simply cancel the event. I also set the text of the "disabled" node to gray so the user has a visual queue.
Problem is - if the event was triggered because a parent node was checked off, the child will remain unchecked (which is correct), but the parent's checkbox remains checked instead of GreyChecked (or unchecked, depending on the other child nodes' states). If anyone has any ideas about how to overcome this I'd love to hear them.
code snippet:
private void mTriStateTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e)
{
if (mRadioButtonComplianceEngine.Checked && !mDisablingSourceNodes)
{
if (e.Node.ForeColor == SystemColors.GrayText)
{
e.Cancel = true;
}
}
}
|
|
|
|
|