473,503 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView Nonsense

I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the result) is
this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}

My code to turn this on is
DirTView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
DirTView.DrawNode += new
DrawTreeNodeEventHandler((DrawTreeNodeEventHandler )TVDrawNode);

Now the problem is that the method TVDrawNode gets called many times to
print the nodes more than once. Sometimes its called with the correct Bounds
and other times Bounds is 0 resulting the the Text for each node being
printed at the upper left corner resulting in a mishmash of text. It does
print correctly though the "second" time through and it only seems to do
this on grandchildren. (I have a parent, a child and an several
grandchildren.)
When I expand the child is when it occures and the first row contains all
the text's for all the nodes while the rest of the nodes are fine. This
means its getting called to draw the node more than once and one of those
times the Bounds is not set properly.

What the heck is going on? Its very frustrating doing this stuff because I
can't seem to find any help on the subject ;/ MSDN is pitiful at describing
how these things work... atleast I can't find anything there that goes into
any more detail than just the descriptions of methods and fields.

Is there something I'm obviously doing wrong?

(I'm not creating a custom treeview control either but just overriding the
"paint" method for the nodes in my app)

Thanks,
Jon
Oct 13 '06 #1
8 5615
http://server6.theimagehosting.com/i...=TreeView1.gif

Heres a link that shows the problem.
Oct 13 '06 #2

"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the result)
is this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}

My code to turn this on is
DirTView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
DirTView.DrawNode += new
DrawTreeNodeEventHandler((DrawTreeNodeEventHandler )TVDrawNode);

Now the problem is that the method TVDrawNode gets called many times to
print the nodes more than once. Sometimes its called with the correct
Bounds and other times Bounds is 0 resulting the the Text for each node
being printed at the upper left corner resulting in a mishmash of text. It
does print correctly though the "second" time through and it only seems to
do this on grandchildren. (I have a parent, a child and an several
grandchildren.)
When I expand the child is when it occures and the first row contains all
the text's for all the nodes while the rest of the nodes are fine. This
means its getting called to draw the node more than once and one of those
times the Bounds is not set properly.

What the heck is going on? Its very frustrating doing this stuff because I
can't seem to find any help on the subject ;/ MSDN is pitiful at
describing how these things work... atleast I can't find anything there
that goes into any more detail than just the descriptions of methods and
fields.

Is there something I'm obviously doing wrong?

(I'm not creating a custom treeview control either but just overriding the
"paint" method for the nodes in my app)

Thanks,
Jon
Strange thing that when I minimize the window and bring it back up
everything works fine ;/
Oct 13 '06 #3
PS

"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the result)
is this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}
Does this help?

When using OwnerDrawAll, however, the DrawTreeNodeEventArgs.Bounds property
encompasses the entire width of the TreeView. In this case, you can access
the hit test region by getting the DrawTreeNodeEventArgs.Node value and
accessing its TreeNode.Bounds property.
>
My code to turn this on is
DirTView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
DirTView.DrawNode += new
DrawTreeNodeEventHandler((DrawTreeNodeEventHandler )TVDrawNode);

Now the problem is that the method TVDrawNode gets called many times to
print the nodes more than once. Sometimes its called with the correct
Bounds and other times Bounds is 0 resulting the the Text for each node
being printed at the upper left corner resulting in a mishmash of text. It
does print correctly though the "second" time through and it only seems to
do this on grandchildren. (I have a parent, a child and an several
grandchildren.)
When I expand the child is when it occures and the first row contains all
the text's for all the nodes while the rest of the nodes are fine. This
means its getting called to draw the node more than once and one of those
times the Bounds is not set properly.

What the heck is going on? Its very frustrating doing this stuff because I
can't seem to find any help on the subject ;/ MSDN is pitiful at
describing how these things work... atleast I can't find anything there
that goes into any more detail than just the descriptions of methods and
fields.

Is there something I'm obviously doing wrong?

(I'm not creating a custom treeview control either but just overriding the
"paint" method for the nodes in my app)

Thanks,
Jon
Oct 13 '06 #4

"PS" <ec***********@hotmail.comwrote in message
news:eo**************@TK2MSFTNGP02.phx.gbl...
>
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
>I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the result)
is this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}

Does this help?

When using OwnerDrawAll, however, the DrawTreeNodeEventArgs.Bounds
property encompasses the entire width of the TreeView. In this case, you
can access the hit test region by getting the DrawTreeNodeEventArgs.Node
value and accessing its TreeNode.Bounds property.
I've tried the TreeNode.Bounds on the e.Nodes and its the same thing except
the indention changes.

i.e., using e.Node.Bounds instead of e.Bounds. Same result except
indentation is alreadly done for me. I think that is what you are getting at
though. Remember, it works fine once I hide the window and bring it back up
;/

Thanks,
Jon

Oct 13 '06 #5
PS

"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
>
"PS" <ec***********@hotmail.comwrote in message
news:eo**************@TK2MSFTNGP02.phx.gbl...
>>
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
>>I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the
result) is this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}

Does this help?

When using OwnerDrawAll, however, the DrawTreeNodeEventArgs.Bounds
property encompasses the entire width of the TreeView. In this case, you
can access the hit test region by getting the DrawTreeNodeEventArgs.Node
value and accessing its TreeNode.Bounds property.

I've tried the TreeNode.Bounds on the e.Nodes and its the same thing
except the indention changes.

i.e., using e.Node.Bounds instead of e.Bounds. Same result except
indentation is alreadly done for me. I think that is what you are getting
at though. Remember, it works fine once I hide the window and bring it
back up
It seems that some hidden nodes upon scrolling or expanding into view
initially have e.Node.Bounds equal to 0 for X, Y, Height and Width. You
should check that these values are not zero before drawing the node.

PS
>
Thanks,
Jon
Oct 13 '06 #6

"PS" <ec***********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
>>
"PS" <ec***********@hotmail.comwrote in message
news:eo**************@TK2MSFTNGP02.phx.gbl...
>>>
"Jon Slaughter" <Jo***********@Hotmail.comwrote in message
news:12*************@corp.supernews.com...
I'm trying to override the default paiting of a treeview but I get bad
results:

My code(well, atleast this is the most simple that reproduces the
result) is this
private void TVDrawNode(Object sender, DrawTreeNodeEventArgs e)
{
e.Graphics.DrawString(e.Node.Text, e.Node.TreeView.Font, Brushes.Black,
e.Bounds.Left, e.Bounds.Top);
}

Does this help?

When using OwnerDrawAll, however, the DrawTreeNodeEventArgs.Bounds
property encompasses the entire width of the TreeView. In this case, you
can access the hit test region by getting the DrawTreeNodeEventArgs.Node
value and accessing its TreeNode.Bounds property.

I've tried the TreeNode.Bounds on the e.Nodes and its the same thing
except the indention changes.

i.e., using e.Node.Bounds instead of e.Bounds. Same result except
indentation is alreadly done for me. I think that is what you are getting
at though. Remember, it works fine once I hide the window and bring it
back up

It seems that some hidden nodes upon scrolling or expanding into view
initially have e.Node.Bounds equal to 0 for X, Y, Height and Width. You
should check that these values are not zero before drawing the node.
Yes, they are sometimes zero but why? Why would the draw routine be called
like that? It would be nice if there was some information on the behavior of
these controls. MSDN does a piss-poor job of describing the workings of
them.

I suppose what might be happening is that the very first time the control is
displayed the TreeView control is not setting up the Bounds properly or
something like that? I really have no idea though ;/ I will try what you
sugggest and see if that fixes(it definately will but might break something
else).

Thanks,
Jon
Oct 13 '06 #7
PS
<snipped>
>It seems that some hidden nodes upon scrolling or expanding into view
initially have e.Node.Bounds equal to 0 for X, Y, Height and Width. You
should check that these values are not zero before drawing the node.

Yes, they are sometimes zero but why? Why would the draw routine be called
like that? It would be nice if there was some information on the behavior
of these controls. MSDN does a piss-poor job of describing the workings of
them.

I suppose what might be happening is that the very first time the control
is displayed the TreeView control is not setting up the Bounds properly or
something like that? I really have no idea though ;/ I will try what you
sugggest and see if that fixes(it definately will but might break
something else).
I don't think it will break anything. When you do something like expand a
node it raises an event to say "this node needs to be drawn". The node may
not of determined it's bounds yet hence the zero values. It could be a race
condition with different events. Sometimes the node has determined it's
bounds when the draw node event fires, sometimes it hasn't.

PS

Oct 14 '06 #8

"PS" <ec***********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
<snipped>
>>It seems that some hidden nodes upon scrolling or expanding into view
initially have e.Node.Bounds equal to 0 for X, Y, Height and Width. You
should check that these values are not zero before drawing the node.

Yes, they are sometimes zero but why? Why would the draw routine be
called like that? It would be nice if there was some information on the
behavior of these controls. MSDN does a piss-poor job of describing the
workings of them.

I suppose what might be happening is that the very first time the control
is displayed the TreeView control is not setting up the Bounds properly
or something like that? I really have no idea though ;/ I will try what
you sugggest and see if that fixes(it definately will but might break
something else).

I don't think it will break anything. When you do something like expand a
node it raises an event to say "this node needs to be drawn". The node may
not of determined it's bounds yet hence the zero values. It could be a
race condition with different events. Sometimes the node has determined
it's bounds when the draw node event fires, sometimes it hasn't.
yeah, it works.

I agree with that but I don't understand why it it would generate those
messages in the first place? Its basically telling us to redraw the nodes
twice but that seems like a waste of messages? I just don't like the idea of
not knowing whats going on for sure. I would wish for good documentation by
those that actually implemented it but that won't happen ;/

If the whole reason I was doing this is because there is no way to have a
checkbox on a per node basis ;/ So if MS screwed up here they could screw up
in other places ;/ (and knowing MS's past history ;/

The old MS-help has very good descriptions of these processes and describes
almost all the inner workings but the newer helps don't give anything like
this.

Thanks,
Jon
Oct 14 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
11470
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
5
19867
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
3
2817
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
6
14169
by: meh | last post by:
I can figure out the total number of nodes in a given tree but what I'd like to know is what is the Selected Nodes relationship to the entire tree i.e This is node n out of nnn nodes. In most of...
6
4913
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
15050
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
3
3800
by: christof | last post by:
I've got a really easy problem, please help me: There are two pages in one I'm creating a TreeView like that: TreeView dbTree = new TreeView(); TreeNode dbTreeRoot = new TreeNode("Root");...
2
7479
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
8
12726
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.