List Info

Thread: C-Sharp (C#) Group: Treeview Node Selection : Show arrow instead of highlighting




C-Sharp (C#) Group: Treeview Node Selection : Show arrow instead of highlighting
user name
2006-04-03 08:23:04
Hi
Got a doubt.
In C# Treeview on selecting a node its backcolor changes to
blue (i.e
it turns blue and gets selected)
Now i want to override this property and show an arrow
instead of the
blue color for the selcted node.
Please let me how this can be done. 

Regards,
Gouri K.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Treeview Node Selection : Show arrow instead of highlighting
user name
2006-04-06 12:53:29
Hi Gouri,

You'll have to override the DrawNode event of the TreeView
like this:

TreeView view;

private void setUpCustomDraw() {
	// The TreeView will still take care of drawing the lines,
pluses,
minuses, etc...
	view.DrawMode = TreeViewDrawMode.OwnerDrawText;
	view.DrawNode += new
DrawTreeNodeEventHandler(view_DrawNode);
}

void view_DrawNode(object sender, DrawTreeNodeEventArgs e) {
	Graphics g = e.Graphics;
	TreeNode node = e.Node;
	int arrowWidth = 10;
	g.DrawString(node.Text, view.Font, Brushes.Black,
e.Bounds.X +
arrowWidth + 2, e.Bounds.Y);
	if(e.State == TreeNodeStates.Selected) {
		// Draw arrow
		Point[] p = new Point[3];
		p[0] = new Point(e.Bounds.Left, e.Bounds.Top + 2);
		p[1] = new Point(e.Bounds.Left, e.Bounds.Bottom - 2);
		p[2] = new Point(e.Bounds.Left + arrowWidth, (e.Bounds.Top
+
e.Bounds.Bottom) / 2);
		g.FillPolygon(Brushes.Black, p);
	}
}

I haven't tested it but the code should look a lot like
this 

Cheers,
Bram Fokke


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )