Windows Develop Bookmark and Share   
 index > Windows Forms General > Last Node on Tree View Missing
 

Last Node on Tree View Missing

The very last node of my tree view is not being displayed. it's there, you just cant see it. Here's the strange part, if I switch my display options under the Display Properties --> Appearance of Windows from Windows XP Style to Windows Classic Style and then run my program again, the last node is there and all is well.

I cannot find anything on how to fix this. I have validated this on several other machines and all exhibit the same behaviour.

HELP!!!

Bill Levine  Thursday, December 21, 2006 12:04 AM
I was able to reproduce it with the code shown in your link. Wow, of all the Visual Styles problems, this one certainly bakes the cake. The problem is reported at Product Feedback but seems to have sorta died there without any response from MSFT.

It certainly is a Visual Styles bug. Oddly, disabling visual styles for just the treeview doesn't fix the problem. The bug appears to be of the off-by-one variety. In classic style, the treeview leaves enough space at the bottom of the list for up to one full row, depending on the vertical control size. With Visual Style enabled it doesn't and the last row can get partially obscured.

Since selectively disabling visual styles didn't work, the only work-around I found was to tweak the vertical size of the control just right so that the last row is displayed full-size. You'll have to tweak it one pixel at a time. I think you can do it in code but haven't tested it extensively. Add this line to the Form_Load event handler:

treeView1.Height = (treeView1.Height / treeView1.ItemHeight) * treeView1.ItemHeight + 3;

nobugz  Thursday, December 21, 2006 4:16 PM
Bizarre problem! Is it just forgetting to display a scrollbar? What happens if you make the control at bit taller? To help you with this, we need to be able to reproduce this on your own PCs; post some code.
nobugz  Thursday, December 21, 2006 6:18 AM

No the scrollbar is there. If you make the control taller is doesn't help. I understand you need to be able to reproduce it, however, all I have done is add items to a Treeview like this.

myData.Tables["Employees"].Clear();

employeeAdapter.SelectCommand.CommandText = sqlString;

employeeAdapter.Fill(myData, "Employees");

foreach (DataRow myRow in myData.Tables["Employees"].Rows)

{

tvEmployees.Nodes.Add(myRow[1].ToString() + " " + myRow[2].ToString());

}

Now if you look at this link, you will see that someone else had this problem, http://www.irgendwie.net/blog/?p=18, there solution was to remove EnableVisualStyles() line in the main(), and yes that does correct the problem, however, that is not what I want to do. If I remove that I lose the ability to have my app change when a user changes their Windows Style. Right now I'm using the WindowsXP Style, again, if I go back to the classic style then it works properly, but none of our client computers use the classic style, they are all using the WindowsXP Style.


Thanks,

Bill

Bill Levine  Thursday, December 21, 2006 3:18 PM
I was able to reproduce it with the code shown in your link. Wow, of all the Visual Styles problems, this one certainly bakes the cake. The problem is reported at Product Feedback but seems to have sorta died there without any response from MSFT.

It certainly is a Visual Styles bug. Oddly, disabling visual styles for just the treeview doesn't fix the problem. The bug appears to be of the off-by-one variety. In classic style, the treeview leaves enough space at the bottom of the list for up to one full row, depending on the vertical control size. With Visual Style enabled it doesn't and the last row can get partially obscured.

Since selectively disabling visual styles didn't work, the only work-around I found was to tweak the vertical size of the control just right so that the last row is displayed full-size. You'll have to tweak it one pixel at a time. I think you can do it in code but haven't tested it extensively. Add this line to the Form_Load event handler:

treeView1.Height = (treeView1.Height / treeView1.ItemHeight) * treeView1.ItemHeight + 3;

nobugz  Thursday, December 21, 2006 4:16 PM
Your code works beautifully. Thank you for the solution. This was driving me crazy and I can't believe there aren't more posts about it out on the WWW. Again thanks and Happy Holidays.
Bill Levine  Thursday, December 21, 2006 5:53 PM

You can use google to search for other answers

Custom Search

More Threads

• How to fix these font size and style problems?
• Drag & Drip File From Explorer
• File open form dialog events
• MultiThreading - Create,Stop & Refersh.
• Difference between Sub Form_Load and Sub New
• listView - with details
• MonthCalendar_DateChanged Event
• 128 Bar Code Printing
• AxMSChart20Lib and MSDATASRC Runtime Error.
• Leave Event