Solved

Custom TreeView

Posted on 2010-11-19
3
1,871 Views
Last Modified: 2013-12-17
Experts,

I`m using VS2008, C#, 3.5

I`m creating a custom TreeView. I just want to change the way it looks. So I created a gradient background by over riding the OnPaintBackground(PaintEventArgs e). This works great.
Now when I try to create the Nodes. I don`t see anything. But the nodes are present, they just flicker for a second. Also when I click on the TreeView, the nodes are activated. It`s just that I don`t see them.

To draw the nodes I`m using

protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = true;
            base.OnDrawNode(e);
            //What goes in here? I might have some wrong code
        }

Help with some code will be greatly appreciated. Thanks - San
0
Comment
Question by:San24
3 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 250 total points
ID: 34174900

I think you need to handle DrawNode event as well where you have to draw the node (when treeview's DrawMode proeprty is set to ownerdraw for custom treeviews). You can refer this link for more details => http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode.aspx
0
 
LVL 8

Assisted Solution

by:dericstone
dericstone earned 250 total points
ID: 34176176
Here's some code to get you started. I extracted this from my more complex code. Let me know if you cannot make it work.
protected override void OnDrawNode(DrawTreeNodeEventArgs e)

    {

      SolidBrush foreBrush = (SolidBrush)SystemBrushes.HighlightText;

      SolidBrush backBrush = (SolidBrush)SystemBrushes.Highlight;

      e.Graphics.FillRectangle(backBrush, e.Bounds);

      e.Graphics.DrawString(e.Node.Text, e.Node.NodeFont, foreBrush,

        Rectangle.Inflate(e.Bounds, 2, 0));

    }

Open in new window

0
 

Author Comment

by:San24
ID: 34176471
@kris_per and dericstone - Let me give that a whirl and get back to you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now