473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TreeView: How to select an item via VBA?

I've just added a new record to the backend DB and reloaded the
TreeView that shows the user all records in the DB.

Now I want to programatically position the TreeView at the newly-added
record and have it that branch of the tree selected.

Anybody know how to do this?

Jul 20 '06 #1
6 20912
Anybody know how to do this?

I tried what seemed like the obvious:

treDeal.Nodes("Whatever").Select

but it always throws a 35601 "Element not found"

Jul 20 '06 #2
Hi Pete,

I hope this can get you started. The tricky part is that none of the
methods I show here show up in the dropdown for the treeview control. I
got a sample of treeview code from the internet somewhere. I
simplified it a bit to illustrate the relationship of the nodes.

This code assumes you have a treeview control on your form called
Treeview0

Private Sub Form_Load()

Me.TreeView0.Nodes.Clear

Me.TreeView0.LineStyle = tvwRootLines
Me.TreeView0.Indentation = 100

Me.TreeView0.Nodes.Add Key:="Main", Text:="myMain"
Me.TreeView0.Nodes.Add Relative:="Main", _
relationship:=tvwChild, Key:="Test", Text:="Test"

Me.TreeView0.Nodes.Add Relative:="Test", _
relationship:=tvwChild, Key:="Test1", Text:="myTest1"

Me.TreeView0.Nodes.Add Relative:="Test1", _
relationship:=tvwChild, Key:="Test1a", Text:="myTest1a"

Me.TreeView0.Nodes.Add Relative:="Test1", _
relationship:=tvwChild, Key:="Test1b", Text:="myTest1b"

Me.TreeView0.Nodes.Add Relative:="Test", _
relationship:=tvwChild, Key:="Test2", Text:="myTest2"

Me.TreeView0.Nodes.Add Relative:="Test", _
relationship:=tvwChild, Key:="Test3", Text:="myTest3"

End Sub
Note: tvwChild and tvwRootLines are constants that are part of the
Treeview control. There are more constants with specific names that are
part of the Treeview control. You can look these up on the internet.
There is a constant for adding images to the list

Me.TreeView0.Style = tvwTreelinesPlusMinusPictureText

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 20 '06 #3
In article <11*********************@75g2000cwc.googlegroups.c om>,
Go**********@FatBelly.com says...
I've just added a new record to the backend DB and reloaded the
TreeView that shows the user all records in the DB.

Now I want to programatically position the TreeView at the newly-added
record and have it that branch of the tree selected.

Anybody know how to do this?

I posted the code I use here:
http://www.psci.net/gramelsp/temp/frmFamilies_code.txt

See Form 4 here. This is an image of the treeview form.
http://www.psci.net/gramelsp/temp/ChurchTemplate.html

All it does it basically use someone elses's code as not in the code
remarks.
Jul 21 '06 #4

Mike Gramelspacher wrote:
http://www.psci.net/gramelsp/temp/frmFamilies_code.txt
Thanks Mike. MyTreview_FindNode(strKey) looks like what I'm trying to
do.

I was trying to do it based on Node.Text. Now it's obvious that I
need to concoct the key and use that.

Jul 23 '06 #5

PeteCresswell wrote:
I was trying to do it based on Node.Text. Now it's obvious that I
need to concoct the key and use that.
Which begs another question: Is there any place for me to squirrel
away data that the user does not see besides .Key?

Right now, I'm embedding a bunch of stuff in .Key that will be
difficult or impossible to back into when I need to do a search.

If I could put it somewhere else and simplify the key, my problem would
be solved.

Jul 23 '06 #6

PeteCresswell wrote:
Is there any place for me to squirrel
away data that the user does not see besides .Key?
Oops!... Frivolous question... my figurative mouth got out of control
before I had the sense to browse the object.

..Tag is my vehicle....

Jul 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: K. Lobe | last post by:
list box based on a POST method to the same page. frm.cmbList.Value=Request.Form("cmbList") doesn't work. When the page loads, it reloads the <SELECT>, so not sure how to get the list to go to...
1
by: kerravon.geo | last post by:
I have a listbox whose rowsource is set to a memo field containing a semi-colon delimited value list. Upon initial opening of the form, I can't select an item from the list. However, if I add a...
1
by: Marc Jennings | last post by:
Hi There is probably a very simple answer to this, but I am not too familiar with the treeView control... I have a treeview control, populated from a database. I want to be able to get the...
5
by: Richard Bond | last post by:
I'm having a lot of trouble programatically selecting a listview item. How do you do this? These didn't work for me in the context of the sub below (that's trying to move up an Item in the...
2
by: tmaster | last post by:
I can detect a right click on my treeview, but SelectedNode.Index points to the last node that was left-clicked. Is there a way for a right-click event of a treeview to update the...
5
by: mabond | last post by:
Hi My project has a form, two list boxes (lstArchive and lstSchedule) and two buttons (btnSendArchive and btnSendSchedule) Each list box represents the content of a directory. The command...
0
by: SirPoonga | last post by:
I am not liking the default behavior the treeview with right clicking. I have a treeview with a context menu assigned to it. When I hold the right mouse button on a node the node is highlighted. ...
4
by: HeavyD | last post by:
I am populating a treeview in C# from a SQL Server 2005 database. Table tree( id int, parent_id int, name varchar(50). The treeview is populated succesfully and when I select a node it is...
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
1
by: gayat jain | last post by:
jsf <h:select item> how i can call bean method one click any select item
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.