The following is my code on a on open evnt of a form containing a treeview.
IN the properties of the treeview I have selected to use check marks.
Currently you can select any node in the treeview and it will check individually with no effect on the parent node.
I need to find a way to force the parent node items to be checked with a child item is checked..
For example….
If the treeview is a function of location and it had three nodes
Area – Row – plot
And a user checked plot 1 in row 2 of area 1
Currently only plot one is checked..I need to make sure that if plot 1 is checked then by default area 1 and row 2 are checked. I do not however want to reverse that so that if if an perent node item is checked then all child nodes are selected.
Here is the code for the event that build the treeview
Private Sub Form_Load()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim nodX As Node
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT AreaID,AreaName FROM tblArea;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add , , "Area " & CStr(rs!AreaID) & " Node", rs!AreaName, 1
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT RowID,AreaID,RowNumber FROM tblRow;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Area " & CStr(rs!AreaID) & " Node", tvwChild, "Row " & CStr(rs!RowID) & " Node", rs!RowNumber, 2
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT PlotID,RowID,Plot FROM tblPlot;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Row " & CStr(rs!RowID) & " Node", tvwChild, "Plot " & CStr(rs!PlotID) & " Node", rs!Plot, 3
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
IN the properties of the treeview I have selected to use check marks.
Currently you can select any node in the treeview and it will check individually with no effect on the parent node.
I need to find a way to force the parent node items to be checked with a child item is checked..
For example….
If the treeview is a function of location and it had three nodes
Area – Row – plot
And a user checked plot 1 in row 2 of area 1
Currently only plot one is checked..I need to make sure that if plot 1 is checked then by default area 1 and row 2 are checked. I do not however want to reverse that so that if if an perent node item is checked then all child nodes are selected.
Here is the code for the event that build the treeview
Private Sub Form_Load()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim nodX As Node
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT AreaID,AreaName FROM tblArea;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add , , "Area " & CStr(rs!AreaID) & " Node", rs!AreaName, 1
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT RowID,AreaID,RowNumber FROM tblRow;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Area " & CStr(rs!AreaID) & " Node", tvwChild, "Row " & CStr(rs!RowID) & " Node", rs!RowNumber, 2
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT PlotID,RowID,Plot FROM tblPlot;"
End With
Do While Not rs.EOF
With Me!TreeViewLocation
.Nodes.Add "Row " & CStr(rs!RowID) & " Node", tvwChild, "Plot " & CStr(rs!PlotID) & " Node", rs!Plot, 3
End With
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub