Treeview - How to determine top visible row?

Gary McMaster

Well-known Member
Joined
Feb 8, 2009
Messages
1,978
Hi Everyone,

I have a treeview control displaying the parent / child relationships of a couple of columns. The scroll bar is enabled for the longer lists. If the user scrolls down the tree, is there a way I can tell which node is displayed at the top of the treeview window?

The ultimate goal is to sync the treeview with a listview control. Am I already headed down the wrong path?

I know of the multi column treeview at VbAccelerator but would rather not use a 3rd party control if I can avoid it.

Thanks in adavance for your help.

Gary
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Gary

Why do you need to work out that particular node?

If the user has drilldown to a particular child node you should be able to go backwards to get the parent nodes.

If it's the parent node you are interested in of course.:)
 
Upvote 0
Hi Norie,

My plan may not be practical. There are 10 or 12 other fields associated with each node that I intend to display in an adjacent listview control. If the user scrolls either control then I need to scroll the other control to match to keep the rows aligned.

I've been studying the methods and properties of the treeview all day and haven't seen anything that I recognized as a means of determining what is currently visible to the user inside the boundaries of the control.

If I can overcome the resistance to using 3rd party (read Non-Microsoft) controls, I may be able to use the perfect solution which is located here:

http://www.vbaccelerator.com/home/v...iew/Multi-Column_TreeView_Control/article.asp

Thanks for the reply.

Gary
 
Upvote 0
Thanks Kris.

The article mentions a version for pre XL2007. Do you happen to know where I could find a copy of the earlier version. I don't have XL2007 available here.

Gary
 
Upvote 0
Gary

As far as I can work out there is no way to get the first visible node of a treeview.

There is GetVisibleCount but that's all you get - a count.

I'm not even sure what's being counted - when I try it with 3 unexpanded top/parent nodes the result isn't 3.

Even when you expand a node the count doesn't seem to change.

The count actually seems to be based on the height of the treeview.

Of course, I might be missing something.:)
 
Upvote 0
Norie,

I've tried the "GetVisibleCount" myself. It seems to work as advertised but it doesn't do anything for me unless I know which node is the first or last member of that "VisibleCount".

There is also an "EnsureVisible" method. I haven't tried it yet, but my first impression is that you might be able to figure it out by forcing the first and/or last node visible (Ensurevisible) and taking the "VisibleCount" into consideration with a little math. Seems that would cause some serious screen flicker though. Perhaps the control also lets you turn off "Screenupdating".

I've also seen mention of binding the "SelectedItem" property of the two controls together to sync them. Just buzzwords to me at the moment but I'm working on it.

Thanks for your interest.

Gary
 
Upvote 0
Gary

As far as I can work out, and I did some light checking, the GetVisibleCount is based on the height of the control.

Even with all the nodes expanded it doesn't change.

Don't know about 'binding' the controls together but you could probably use the SelectedItem from the treeview to change what's in the listview.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top