Tree View MS-Access 2003

C

cehrenre

Have a project for work thats driving me nuts! Most of the work is complete
but I have been asked to build a tree view. I figured out how to load the
root and child nodes. I can collapse/expand all as needed via buttons. My
problem is that I have checkboxes=True. I cannot figure out how to have all
the child nodes check boxes set to True if its parent is checked (and
conversely, when the parent is unchecked, then all children should be
unchecked).

This is driving me nuts...Can anyone help me?
 
J

John Gray

Hi,

The information below should get you moving in the right direction.
The method and property names, and sample code are based on
the Delphi/Pascal wrapper for the Windows Treeview. You should
be able to find the equivalents in the VB(A) help for the Treeview.

Essentially, what you want to do is check the status
(checked/unchecked) of a Parent node, then get the Child count,
then walk through the child nodes, setting each accordingly.

Suggestions on finding more info...
- AccessMonster has a number of "Treeview" related links
( http://www.accessmonster.com )
- I found this link to a demo Treeview on AccessMonster:
( http://www.pointltd.com/Downloads/Details.asp?dlID=36 )
- You might want to ask your question in the
(Access) formscoding and modulescoding newsgroups
- And of course, the Microsoft website
(http://microsoft.com)

hth,
John

-------------------------

o) A treeview node has these useful properties:
- HasChildren (returns boolean true/false)
- Count (returns integer, the number of child nodes for *this* node.
- Index (integer, the relative position of the specified node)
- Item (provides access to a child node by its position in the list of
child nodes)
- Selected (returns the current selected node, from which you can
get Index, Text (label (text) value assigned to node), and other
values)

o) And a treeview node has these useful methods:
- GetFirstChild (returns the first child Treenode)
- GetNextChild (etc...)
- GetLastChild

o) If a node has children, they are indexed 0...n, with respect to the
Parent node.

o) Some sample (Delphi) code:
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
{ This will add labels for all the child nodes (of the selected parent node)
into a listbox }
for i := 0 to (MyTreeView.Selected.Count - 1) do
ListBox1.Items.Add(MyTreeView.Selected.Item.Text);

{ This will display a messagebox for each child, showing the
Index number }
for i := 0 to (MyTreeView.Selected.Count - 1) do
Showmessage('Item: ' + IntToStr(MyTreeView.Selected.Item.Index));
end;


======================

"cehrenre" wrote...
 
C

cehrenre

Outstanding links. You 've made my day! Here is my code for anyone else to
use should they run into this problem. Thanks Again.

Private Sub xTree_NodeCheck(ByVal Node As Object)

Dim nChild As MSComctlLib.Node, intI As Integer
Dim objTree As TreeView

Set nChild = Node.Child
For intI = 1 To Node.Children
If Node.Checked = True Then
nChild.Checked = True
Else
nChild.Checked = False
End If
Set nChild = nChild.Next
Next intI

End Sub

John Gray said:
Hi,

The information below should get you moving in the right direction.
The method and property names, and sample code are based on
the Delphi/Pascal wrapper for the Windows Treeview. You should
be able to find the equivalents in the VB(A) help for the Treeview.

Essentially, what you want to do is check the status
(checked/unchecked) of a Parent node, then get the Child count,
then walk through the child nodes, setting each accordingly.

Suggestions on finding more info...
- AccessMonster has a number of "Treeview" related links
( http://www.accessmonster.com )
- I found this link to a demo Treeview on AccessMonster:
( http://www.pointltd.com/Downloads/Details.asp?dlID=36 )
- You might want to ask your question in the
(Access) formscoding and modulescoding newsgroups
- And of course, the Microsoft website
(http://microsoft.com)

hth,
John

-------------------------

o) A treeview node has these useful properties:
- HasChildren (returns boolean true/false)
- Count (returns integer, the number of child nodes for *this* node.
- Index (integer, the relative position of the specified node)
- Item (provides access to a child node by its position in the list of
child nodes)
- Selected (returns the current selected node, from which you can
get Index, Text (label (text) value assigned to node), and other
values)

o) And a treeview node has these useful methods:
- GetFirstChild (returns the first child Treenode)
- GetNextChild (etc...)
- GetLastChild

o) If a node has children, they are indexed 0...n, with respect to the
Parent node.

o) Some sample (Delphi) code:
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
{ This will add labels for all the child nodes (of the selected parent node)
into a listbox }
for i := 0 to (MyTreeView.Selected.Count - 1) do
ListBox1.Items.Add(MyTreeView.Selected.Item.Text);

{ This will display a messagebox for each child, showing the
Index number }
for i := 0 to (MyTreeView.Selected.Count - 1) do
Showmessage('Item: ' + IntToStr(MyTreeView.Selected.Item.Index));
end;


======================

"cehrenre" wrote...
Have a project for work thats driving me nuts! Most of the work is complete
but I have been asked to build a tree view. I figured out how to load the
root and child nodes. I can collapse/expand all as needed via buttons. My
problem is that I have checkboxes=True. I cannot figure out how to have all
the child nodes check boxes set to True if its parent is checked (and
conversely, when the parent is unchecked, then all children should be
unchecked).

This is driving me nuts...Can anyone help me?
 
M

Makelei

Hi,
Thanks for this code -it works well.
I have a question. Given code is following from Parent to Children. I have a
situation that I have Parent - Child - Child.

What kind of modification should I make that it works the same way?
How would I be able to get a list of all the ones that CheckBox is activated?

As you are able to notice I am a novice in programming ;o(

Thanks in advance
MakeLei

cehrenre said:
Outstanding links. You 've made my day! Here is my code for anyone else to
use should they run into this problem. Thanks Again.

Private Sub xTree_NodeCheck(ByVal Node As Object)

Dim nChild As MSComctlLib.Node, intI As Integer
Dim objTree As TreeView

Set nChild = Node.Child
For intI = 1 To Node.Children
If Node.Checked = True Then
nChild.Checked = True
Else
nChild.Checked = False
End If
Set nChild = nChild.Next
Next intI

End Sub

John Gray said:
Hi,

The information below should get you moving in the right direction.
The method and property names, and sample code are based on
the Delphi/Pascal wrapper for the Windows Treeview. You should
be able to find the equivalents in the VB(A) help for the Treeview.

Essentially, what you want to do is check the status
(checked/unchecked) of a Parent node, then get the Child count,
then walk through the child nodes, setting each accordingly.

Suggestions on finding more info...
- AccessMonster has a number of "Treeview" related links
( http://www.accessmonster.com )
- I found this link to a demo Treeview on AccessMonster:
( http://www.pointltd.com/Downloads/Details.asp?dlID=36 )
- You might want to ask your question in the
(Access) formscoding and modulescoding newsgroups
- And of course, the Microsoft website
(http://microsoft.com)

hth,
John

-------------------------

o) A treeview node has these useful properties:
- HasChildren (returns boolean true/false)
- Count (returns integer, the number of child nodes for *this* node.
- Index (integer, the relative position of the specified node)
- Item (provides access to a child node by its position in the list of
child nodes)
- Selected (returns the current selected node, from which you can
get Index, Text (label (text) value assigned to node), and other
values)

o) And a treeview node has these useful methods:
- GetFirstChild (returns the first child Treenode)
- GetNextChild (etc...)
- GetLastChild

o) If a node has children, they are indexed 0...n, with respect to the
Parent node.

o) Some sample (Delphi) code:
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
{ This will add labels for all the child nodes (of the selected parent node)
into a listbox }
for i := 0 to (MyTreeView.Selected.Count - 1) do
ListBox1.Items.Add(MyTreeView.Selected.Item.Text);

{ This will display a messagebox for each child, showing the
Index number }
for i := 0 to (MyTreeView.Selected.Count - 1) do
Showmessage('Item: ' + IntToStr(MyTreeView.Selected.Item.Index));
end;


======================

"cehrenre" wrote...
Have a project for work thats driving me nuts! Most of the work is complete
but I have been asked to build a tree view. I figured out how to load the
root and child nodes. I can collapse/expand all as needed via buttons. My
problem is that I have checkboxes=True. I cannot figure out how to have all
the child nodes check boxes set to True if its parent is checked (and
conversely, when the parent is unchecked, then all children should be
unchecked).

This is driving me nuts...Can anyone help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top