TreeView starts with useless Horizontal Scrollbar

B

Benny Raymond

Does anyone know what causes a treeview to sometimes start with a
horizontal scrollbar that has no reason to be there, and will not go
away until you size into the nodes and then back out?

Anyone know how to correct this bug?

My treeview was working fine until I added it to a tab page :(

Thanks,
Benny
 
B

Benny Raymond

Did a lot of research and discovered that this is a known issue in .net
- it's supposedly fixed in 2005 but in earlier versions you cannot put
nodes in a tree view until after it has been created... Since I put the
treeview into a tabpage the same thing occured because i was loading
nodes since I didn't show the page until after I loaded the nodes in.

So I guess i'm going to move my tree view into it's own form and make an
MDI with custom tabs ... unless anyone else has a good idea?
 
G

Guest

Hi Benny,
I was having the same problem recently even using VS 2005. I found a work
around it is a little bit of a hack but it works perfectly. Basically what
you have to do is make the width of your control small such that the scroll
bar is really needed i.e. set the width to 20, then load your nodes. Do the
first two things then after you have done that programatically set the width
back to the normal width you originally wanted and the scrollbar will not
apppear.

The real trick though is you cannot set the width twice in the same meothd,
you have to set it to a larger width in the load method of the control i.e.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.treeView1.Width = 20;
this.treeView1.Nodes.Add("bob");
}

private void Form1_Load(object sender, EventArgs e)
{
this.treeView1.Nodes.Add("bob2");

this.treeView1.Width = 200;
}
}

Hope that helps
Mark R Dawson
http://www.markdawson.org
 

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