Skip to content


How to fix: “last item not visible in TreeView”

As reported this problem is somehow related to Visual Styles usage in .Net. This is known issue and is recognized by Microsoft. There are a few ways to fix this problem. Let’s start with the easiest one. Note that this problem occurs in cases when treeView is dynamically populated.

Disabling visual styles is the easy solution, but not suitable in case you need visual styles to be enabled.

Another solution is to always use treeView.BeginUpdate() (before) and treeView.EndUpdate()  (after) you populate your treeView. This not only that solves the problem with the missing last item it also improves performance. But it should be used carefully and watch out not to overuse it . Here is a bad example:

1
2
3
4
5
6
foreach (TreeNode node in treeView.Nodes)
{
    treeView.BeginUpdate();
    node.Text += node.Text + (" (Selected) ");
    treeView.EndUpdate();
}

Calling treeView.EndUpdate() causes the treeView to be redrawn but if we call it to often we end up with the same issue we had in the first place, performance.
Correct example would be:

1
2
3
4
5
6
treeView.BeginUpdate();
foreach (TreeNode node in treeView.Nodes)
{
    node.Text += node.Text + (" (Selected) ");
}
treeView.EndUpdate();

Hope this helps someone struggling with the similar issue.
If anyone has something to add or improve post a comment.

Posted in .NET.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. click here says

    Click on this link to see full info



Some HTML is OK

or, reply to this post via trackback.