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
 
Norie,

The "GetVisibleCount" count is working for me. I've no idea why it doesn't work for you.

I'm thinking a viable workaround might be to switch off scroll bars in both controls and then add my own scroll bar. That way I may be able to cause both controls to scroll synchronously with my "Common Scrollbar" in conjunction with the "EnsureVisible" method that appears to be available in both controls. The GetVisbleCount might also come in handy to control the visibility of my common scroll bar. Usually most of the nodes will fit in the window but on occasion the Nodes.Count will > GetVisibleCount.

Thanks again for your input. It is much appreciated.

Gary
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Gary

How are you using it?

You mentioned earlier some 'math'?

Perhaps I am missing something, probably something obvious.

By the way, wouldn't it be simpler to base what's displayed in the listview on what the user has selected, not what is visible in the treeview?
 
Upvote 0
How are you using it?

Nothing special, I'm just loading the tree with more nodes than I know will fit in the window and asking it how many are visible. The math I mentioned was just a thought that if I had a minimum of adequate parameters I could calculate which nodes are showing.

I have found that I can iterate the Nodes collection and check the .Visible property. Sure enough, the first one that returns True always seems to be the node at the top of the window. I still haven't found a way to hook into the scroll bar which is what I think I really need. I believe I can find the top visible node now but still won't know when it is necessary to do so to realign the listview.

simpler to base what's displayed in the listview on what the user has selected

I need something similar to what is shown here:

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

The short answer is the user has already made their selection before the tree is even populated. This project is meant to generate a multi level bill of materials for a retired database. The user has already requested a BOM for (ancient) assembly "xyz" and that is what I am loading into the tree. The part number(s) alone aren't good enough. I must at least provide the part description, quantity, revision and perhaps a few other fields in the adjacent "ListView" control. I am looking that data up in another large "Part Master" table.

We no longer have the program that originally generated the tables (or BOMs), only the tables themselves. I have already implemented all of this in Excel using cell indents to produce a printable display very much like that shown at the link above. Drawing the lines to connect the nodes using autoshapes or unicode characters (fluff) is cumbersome and in the end the user cannot expand or collapse the nodes. Otherwise, it is already working well.

Also, the product structure table is more than 150K records. I had to span this table across 3 sheets in Excel (XL2000) order to have all assemblies that existed in the old database available. If I can replicate what I have already done in Excel using these controls (or others) I may be able to move these tables to Access or even create a standalone executable.

Any selections that the user might make in the tree will be just added fluff that will open the CAD drawing or component specification or provide a "where used" function. The Excel version of this project already has these features and they are often used. I suppose the users will insist that they be included.

Thanks very much for your continued interest.

Gary
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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