TreeView doesn't show last item

C

Christof Nordiek

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.ToString());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.Windows.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);
}
}
}
 
G

Guest

Christof Nordiek said:
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
 
C

Christof Nordiek

Michael Nemtsev said:
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.ToString());
}
}
[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.Windows.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);
}
}
}
 
C

chanmm

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
 
C

Christof Nordiek

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 said:
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 said:
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.ToString());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.Windows.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);
}
}
}
 
C

Christof Nordiek

Hi russ,

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

russ said:
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.ToString());
}
treeView1.EndUpdate();

Got the idea from here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148930&SiteID=1

Russ

Christof said:
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.ToString());
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
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.Windows.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);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top