 |
|
 |
In drawRootItem:
using (Brush selBrush = new SolidBrush(SystemColors.ButtonFace))
...
using (LinearGradientBrush lgBrush = new LinearGradientBrush(
e.Bounds, SystemColors.ButtonHighlight, SystemColors.ButtonShadow, LinearGradientMode.Vertical))
This takes it from your System Colors, so it blends better with the OS.
In public Toolbox():
this.mGroupHeaderFont = new Font(this.Font, FontStyle.Bold);
this.ShowLines = false;
this.HotTracking = true;
this.FullRowSelect = true;
this.DrawMode = TreeViewDrawMode.OwnerDrawAll;
this.HideSelection = false;
this.ItemHeight = 20;
If we have to do this stuff anyway, why not put it in the constructor?
|
|
|
|
 |
|
 |
Hello PRMan!!!,
you're right. I'll post an updated version of this control within the next weeks that will contain your suggestion.
The new version will also be flicker free and the height of each node may be set individual.
best regards, Popangler
|
|
|
|
 |
|
 |
Hi Popangler,
First of all, I want to thank you for this nice article.
This is what I am looking for.
But I want to have varying height of items.
Treeview.ItemHeight property sets the height for all the items evenly.
I tried with TVM_SETITEMHEIGHT message but could not get the desired results.
Can you please help me out with some clues/code snippets?
Thanks and regards
Prakash.
|
|
|
|
 |
|
 |
Hello rakash Invent,
your requested feature will be included in the next update.
|
|
|
|
 |
|
 |
Hi im a vb.net programmer and I was wondering if you could help me add specific items to the list. For example i want to be able to add the parent nodes for groups and there childs at runtime with out having to do a add group and add child button. how ever i try it it keeps giving me a error about setting new istance or something.
Please help Ty
Eric Allen
|
|
|
|
 |
|
 |
how to draw a decision tree using asp .net
|
|
|
|
 |
|
 |
Hi,
Great job by the way; however there is a slight problem I had with it, which is follows:
If you use the Nodes collection editor to add the Groups and GroupItems to the component at runtime it throws a NullReference exception from the OnBeforeSelect method . Now at runtime, if you handle Activated event then you can add the groups and group items without any problems.
Sincerely,
Angelo
|
|
|
|
 |
|
 |
Hello Angelo,
please try following code to fix this issue (not tested!):
protected override void OnBeforeSelect(TreeViewCancelEventArgs e)
{
if (e.Node != null && e.Node is VSTreeNode
&& !(e.Node as VSTreeNode).Enabled)
{
e.Cancel = true;
}
base.OnBeforeSelect(e);
}
Best regards,
Popangler
|
|
|
|
 |
|
 |
hi there,
I've just downloaded the archive from this page and tried it out... it seems to me the problem with clicking on the +/- sign has not been solved yet. sometimes only the second click expands or collapses the node.
Petru
|
|
|
|
 |
|
 |
Column + column how. Please help me
child item ( column numbers 1 +) how
|
|
|
|
 |
|
 |
hi, i tried to make each group's size bigger but I couldn't. Is it possible to make them bigger?
When I use this toolbox in a maximized window, they seem very little.
|
|
|
|
 |
|
 |
You can only change the height of all items. As far as i known not only the root items.
To realize that, you have to override the WndProc method, and then modify the parameters of the TVM_SETITEMHEIGHT message.
Add this code to the Toolbox class to implement it:
#region Private consts
private const int TVM_SETITEMHEIGHT = 0x111B;
#endregion
#region Private fields
private int mItemHeight;
#endreigon
#region Public properties
public new int ItemHeight
{
get
{
return this.mItemHeight;
}
set
{
if (value > 0 && this.mItemHeight != value)
{
this.mItemHeight = value;
this.Invalidate();
}
}
}
#endregion
#region Protected methods
protected override void WndProc(ref Message m)
{
if (m.Msg == TVM_SETITEMHEIGHT)
{
m.WParam = (IntPtr)(this.mItemHeight);
}
base.WndProc(ref m);
}
#endregion
#region Constructor
public ToolBox()
{
this.mItemHeight = 24; }
#endregion
|
|
|
|
 |
|
 |
Can i display a full Tree under each group member? Please help
|
|
|
|
 |
|
 |
Yes you can. This is quite easy. You have to modify the OnDrawNode methods. E.g. like this:
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{
if (e.Node.Level == 0)
{
drawRootItem(e);
}
else
{
// Draw default nodes..
e.DrawDefault = true;
}
}
In this case only the root items will be drawn like the VS 2005 ToolBox, but each subitem will be drawn as a default treeview item. You may also modify the drawItem method to create "sub-tree".
|
|
|
|
 |
|
 |
Really Thanking you for the snippet .. it worked... But I still have some more requirement only to make the control perfect..
1. can I show the grid lines of the sub item that are in tree mode.. they seem to be hidden away
2. Can I show the sub item node value as half bold.. like for example "My Name" where name is BOLD and My is normal..
can I color the nodes in different colors...
3. can I change the color of root node Groups i.e the main items..Programmatically
I know I have asked for too much... but this is a perfect control i have see.. Please help me to get these features within this
|
|
|
|
 |
|
 |
Hello shagunk65,
1. Yes, you can. But you have to draw the lines by yourself. Just implement the needed code in the drawItem method.
2. Yes, that's alos possible. Create another fonts (like the mGroupHeaderFont). Make it bold and use this font if you want to draw some text as bold. One way to do this is to parse some kind of bb code within the text (maybe not the best way). E.g
First example:
newSubItem.Text = "Hello [B]world[/B]!";
With simple reguar expression it should be possible to filter these code tags out to use another font for bold text:
(Note: this is not a generic sample!)
// Assuming the subItem text is "Hello [B]world[/B]!"
// the bold font
Font boldFont = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
// The regular expression for bold tags:
Regex rgxBold = new Regex("(.*)(\[[bB]\])(.*)(\[/[bB]\])(.*)");
Match mtcBold = rgxBold.Match(subItem.Text);
Rectangle tmpRect = e.Bounds;
if (mtcBold.Success)
{
// Write normal text:
e.Graphics.DrawString(mtcBold.Groups[1].Value, this.Font, SystemBrushes.ControlText, tmpRect.Location);
// Increase tmpRect:
tmpRect.Left += (int)e.Graphics.MeasureString(mtcBold.Groups[1].Value, this.Font);
// now write the bold part of the text:
e.Graphics.DrawString(mtcBold.Groups[3].Value, boldFont, SystemBrushes.ControlText, tmpRect.Location);
// Increase tmpRect:
tmpRect.Left += (int)e.Graphics.MeasureString(mtcBold.Groups[3].Value, boldFont);
// Write normal text again:
e.Graphics.DrawString(mtcBold.Groups[5].Value, this.Font, SystemBrushes.ControlText, tmpRect.Location);
// Increase tmpRect:
tmpRect.Left += (int)e.Graphics.MeasureString(mtcBold.Groups[5].Value, this.Font);
// ...
}
Note this is just an example and it is not tested. You hve to check for empty group in the Match and it should be bether write a generic method for that. To change the color of some parts in the subnote text, just implement more bb codes e.g. [CBlue]BlueText[/CBlue]] and replace the brushes in the e.graphics.DrawString method with the correct color.
3. Yes you can. At this time i use SystemBrushes.ControlText for that. To change the color, create a private field called Color mRootNodecolor = SystemColors.ControlText; and Brush mRootNodeTextBrush = new SolidBrush(SystemColors.ControlText); in the private field reion of my code. Further create a pubic property like this:
Public color RootNodeColor
{
get
{
return this.mRootNodeColor;
}
set
{
this.mRootNodeColor = value;
this.mRootNodeTextBrush = new SolidBrush(this.mRootNodeColor);
Invalidate();
}
}
Now you can change the color of all root items using toolBoxControl.RootNodeColor = Color.Red;
Second Example:
You can improve the VSTreeNode class of the ToolBox. Add some more properties like color, bold-text-parts, ...
In the itemDraw method you can call a custom draw method of the VSTreeNode, so each node will be drawn by itself. This will be much easier to handle stuff like bold or colored text parts.
All these points you wrote will be very well improvments of the control. I think i can implement these features the next few day. (But for now it's over.. i've to go to a bbq ^^)
Best regards popangler
|
|
|
|
 |
|
 |
I wish I could have the integrated Tool, It would really help... actually i am not a C# coder and mainly a VB.net coder....
Request you to helpme...
Best Regds
|
|
|
|
 |
|
 |
I got everything else working except for making half the node BOLD. Can you help me with the code
|
|
|
|
 |
|
 |
Hi Popangler
Very nice little treeview sample... 5 from me.
|
|
|
|
 |
|
 |
Thanks a lot.
|
|
|
|
 |