By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

TreeView doesn't show last item

P: n/a
Hi all,

in my WinForm-Application i have a strange problem with the TreeView
Control.
As you can see in the samplecode below, i fill the TreeView by adding some
nodes with sub nodes. (The subnodes don't matter in the first place.)
After that, when i scroll totally to the bottom, the last item (the 9) rest
almost totally invisable. This problem disappears, when i open (and close)
one of the nodes. (The sample code uses subnodes only to demonstrate this.
The main problem is the same without the subnodes.)

Does anyone know, why this happens? Is there a solution/workaround to this
problem?

Here the sample code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}
Oct 12 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Christof Nordiek" wrote:
>when i scroll totally to the bottom, the last item (the 9) rest
almost totally invisable.
What do u mean? You code works fine without hiding anything.

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Oct 12 '06 #2

P: n/a
"Michael Nemtsev" <ne*****@msn.comschrieb im Newsbeitrag
news:FC**********************************@microsof t.com...
>"Christof Nordiek" wrote:
>>when i scroll totally to the bottom, the last item (the 9) rest
almost totally invisable.

What do u mean? You code works fine without hiding anything.

--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do
not
cease to be insipid." (c) Friedrich Nietzsche
Hi Micheal,

on futher investigation i found out, this depends on the visual styles. It
doesn't happen with Windows classic style but f.e. with Windows XP style it
does. Do be exact, it depends on the style, when the form opend resp. was
filled.

Also i should have mentioned, that i used VS 2005. Though i suppose you also
used since the code doesn't compile with VS 2003.

Below i repost the code that is compilable with both. On VS2003 it works
fine on VS2005 it shows the mentioned phenomenon (dependung on Visual
Styles).

using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}


Oct 12 '06 #3

P: n/a
for (int i = 0; i < 10; i++)

If you mean last one is not 10 it is exactly correct because 10 cannot be
lesser than 10. If you want to should 10 using <= 10

chanmm

"Christof Nordiek" <cn@nospam.dewrote in message
news:e%****************@TK2MSFTNGP05.phx.gbl...
Hi all,

in my WinForm-Application i have a strange problem with the TreeView
Control.
As you can see in the samplecode below, i fill the TreeView by adding some
nodes with sub nodes. (The subnodes don't matter in the first place.)
After that, when i scroll totally to the bottom, the last item (the 9)
rest almost totally invisable. This problem disappears, when i open (and
close) one of the nodes. (The sample code uses subnodes only to
demonstrate this. The main problem is the same without the subnodes.)

Does anyone know, why this happens? Is there a solution/workaround to this
problem?

Here the sample code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}


Oct 12 '06 #4

P: n/a
No i'm not speaking about the 10.
If you read my post well you will see that i'm talking about the 9.
The phenomenon prescribed is dependent an from the visual styles (look in my
response to Michael Nemtsev)
"chanmm" <ch*****@hotmail.comschrieb im Newsbeitrag
news:OX**************@TK2MSFTNGP02.phx.gbl...
for (int i = 0; i < 10; i++)

If you mean last one is not 10 it is exactly correct because 10 cannot be
lesser than 10. If you want to should 10 using <= 10

chanmm

"Christof Nordiek" <cn@nospam.dewrote in message
news:e%****************@TK2MSFTNGP05.phx.gbl...
>Hi all,

in my WinForm-Application i have a strange problem with the TreeView
Control.
As you can see in the samplecode below, i fill the TreeView by adding
some nodes with sub nodes. (The subnodes don't matter in the first
place.)
After that, when i scroll totally to the bottom, the last item (the 9)
rest almost totally invisable. This problem disappears, when i open (and
close) one of the nodes. (The sample code uses subnodes only to
demonstrate this. The main problem is the same without the subnodes.)

Does anyone know, why this happens? Is there a solution/workaround to
this problem?

Here the sample code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToS tring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fal se);
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Wi ndows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}



Oct 12 '06 #5

P: n/a
I've solved this putting BeginUpdate & EndUpdate around the population
code:

treeView1.BeginUpdate();
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
treeView1.EndUpdate();

Got the idea from here:
http://forums.microsoft.com/MSDN/Sho...48930&SiteID=1

Russ

Christof Nordiek wrote:
Hi all,

in my WinForm-Application i have a strange problem with the TreeView
Control.
As you can see in the samplecode below, i fill the TreeView by adding some
nodes with sub nodes. (The subnodes don't matter in the first place.)
After that, when i scroll totally to the bottom, the last item (the 9) rest
almost totally invisable. This problem disappears, when i open (and close)
one of the nodes. (The sample code uses subnodes only to demonstrate this.
The main problem is the same without the subnodes.)

Does anyone know, why this happens? Is there a solution/workaround to this
problem?

Here the sample code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Win dows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}
Oct 13 '06 #6

P: n/a
Hi russ,

thanks, that works!!
I suppose, they should be could anyway (though only for performance
reasens).

"russ" <ru*****************@gmail.comschrieb im Newsbeitrag
news:11**********************@f16g2000cwb.googlegr oups.com...
I've solved this putting BeginUpdate & EndUpdate around the population
code:

treeView1.BeginUpdate();
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToSt ring());
}
treeView1.EndUpdate();

Got the idea from here:
http://forums.microsoft.com/MSDN/Sho...48930&SiteID=1

Russ

Christof Nordiek wrote:
>Hi all,

in my WinForm-Application i have a strange problem with the TreeView
Control.
As you can see in the samplecode below, i fill the TreeView by adding
some
nodes with sub nodes. (The subnodes don't matter in the first place.)
After that, when i scroll totally to the bottom, the last item (the 9)
rest
almost totally invisable. This problem disappears, when i open (and
close)
one of the nodes. (The sample code uses subnodes only to demonstrate
this.
The main problem is the same without the subnodes.)

Does anyone know, why this happens? Is there a solution/workaround to
this
problem?

Here the sample code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TrewViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.TreeView treeView1;
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
for (int i = 0; i < 10; i++)
{
treeView1.Nodes.Add(i.ToString()).Nodes.Add(i.ToS tring());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fal se);
Application.Run(new Form1());
}
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Wi ndows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeView1.Location = new System.Drawing.Point(13, 13);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(267, 120);
this.treeView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
}
}

Oct 13 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.