Solved

Replacing a node on a TreeView control

Posted on 2004-09-29
4
745 Views
Last Modified: 2008-02-01
Hello,

Semiconductor material grown in crystals; the crystals are then cut first into sections, then each section into wafers. A crystal of say, 350mm length, could be cut at 100mm and 200mm creating three sections labeled 0/100, 100/200, 200/350. Wafers cut from the 0/100 section are numbered 1, 2,...100; from the 100/200 section they're numbered 101, 102,...,200  and so on.

I am using a treeview control to display the records for the crystals. Top level (parent) is the crystal itself, next level (child) is sections of the crystal, and the last level (grandchild) are the wafers.

A crystal section can be taken from inventory and cut into two pieces. For example, the 100/200 section can be cut at 175 creating two sections: 100/175, and 175/200. Any wafer records for the original section must be edited so that they will stay associated with the appropriate new section (i.e. wafer 120 must end up a child of the 100/175 section, while wafer 180 must end up a child of the 175/200 section).

All of this works fine.  My problem is at the last step where I want to update the treeview to reflect the change. You can't just requery the control. Also (and please correct me if I'm wrong here), the treeview just represents a view of the data - changing the tree doesn't change the data. That is to say, the data manipulation and the treeview manipulation are done separately.  

I am attempting to:

1. delete the selected section from the treeview
2. add the two new sections in its place
3. populate each new section (add the wafers)

I am getting stuck, mainly I think with the treeview syntax.  Here's most of what I have so far...

Dim objTree As TreeView
Dim nCurrentTreeNode, currentnode, pnode As node


Set objTree = Forms!frmFabrication!tvCrystal.Object

<data manipulation code>

' treeview manipulation
        Set pnode = objTree.SelectedItem.Parent
        objTree.Nodes.Remove (objTree.SelectedItem.Key)
        Set currentnode = objTree.Nodes.Add(pnode, tvwChild, "c" & sectionID, sectionNo)
            'Add any wafers for this section.
 (*)   AddGrandChildren currentnode, currentnode.Key
        Set currentnode = objTree.Nodes.Add(pnode, tvwChild, "c" & newsectionID, newsectionNo)
        'Add any wafers for this section.
        AddGrandChildren currentnode, currentnode.Key
        currentnode.Expanded = True
        currentnode.Selected = True

<then come closing statements>

<The AddGrandChildren routine...>

Sub AddGrandChildren(nodBoss As node, CSN)
    On Error GoTo ErrAddGrandChildren

    Dim nodCurrent As node
    Dim objTree As TreeView
    Dim bk As String
    Dim db As Database
    Dim rst As Recordset

    'Create a reference to the TreeView control.
    Set objTree = Me!tvCrystal.Object
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("SELECT * FROM qryFabricationList2 WHERE [XtalSectionID]=" & CSN)
    Do Until rst.EOF
        'Extract the wafer name.
        strText = rst![FabWaferNo]
        'Add as a child node to the tree.
        Set nodCurrent = objTree.Nodes.Add(nodBoss, tvwChild, "g" & _
            rst![FabWaferNo], rst![WaferNumber])
        'Find the next section.
        rst.MoveNext
    Loop
   
    rst.Close
    Set rst = Nothing

ExitAddGrandChildren:
    Exit Sub

ErrAddGrandChildren:
    MsgBox "Can't add child:  " & Err.Description, vbCritical, _
        "AddGrandChildren(nodBoss As Node) Error:"
    Resume ExitAddGrandChildren
End Sub

<end code>

The code gets to (*) and then I get an error: ByRef argument type mismatch.

Where am I going wrong?

Firebird-sc

0
Comment
Question by:firebird-sc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 190 total points
ID: 12183311
Try:
Dim nCurrentTreeNode As Node, currentnode As Node, pnode As node

At present, your first two vars are dimmed as variants, not node objects. Does this make a difference?
0
 
LVL 2

Author Comment

by:firebird-sc
ID: 12184394
Yes! It did make a difference.  I thought the way I had it before it would set all three to Node objects.

thank you very much! I was stuck on that for a while and there's not a lot out there on the TreeView to reference.

firebird-sc
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12184428
It's actually a limitation of VBA. Unless you include the As <data type> against each variable name, the variable is declared as a variant. For example:

Dim I,J,K As Long
will only dim K as long, the other two are variants. You'd need:
Dim I As Long, J As Long, K As Long
0
 
LVL 2

Author Comment

by:firebird-sc
ID: 12184498
It's never given me a problem until now - I guess historically most of my variables have been variants!  

In ASP, on the other hand, I get errors when I INCLUDE the "As <datatype>" part, so I write all declarations:

dim var1
dim var2
dim var3
etc.

Seems kind of loose and sloppy to me, but it works.

Thanks again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question