Results 1 to 3 of 3

Thread: NodeClick is killing me

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    115

    NodeClick is killing me

    Hi

    I am working with Listview and I can call the record from Listview into textbox

    But the Treeview ?????
    I am traing to use this to call data from database when I click on the treeview but when I click on the top record I get data from database, I only want to get data when I select the Child

    But I only get the 1 data in database if I click on somthing

    Call DisplayItem(Node)

    Private Sub DisplayItem(ByVal nodDisplayedNode As Node)

    Dim rsDisplay As ADODB.Recordset
    Set rsDisplay = New ADODB.Recordset
    strSQL = "Select * from Produto"
    rsDisplay.Open strSQL, cnn, adOpenStatic, adLockOptimistic
    Nafn.Text = IIf(IsNull(rsDisplay.Fields("COD_GRUPO")) = True, "", rsDisplay.Fields("COD_GRUPO"))

    End Sub


    -----TREEVIEW-----------------------
    This is the sample I am use to call data from database

    Dim TotalProd As Long
    Dim db As Database
    Dim rs As Recordset

    Dim dbProdutos As Recordset
    Set db = OpenDatabase(App.Path + "\2000.mdb")

    Screen.MousePointer = 11
    DoEvents

    Set dbGrupoProduto = db.OpenRecordset("SELECT * FROM Grupo_Produto ORDER BY NOME_GRUPO", dbOpenSnapshot)

    With TreProdutos


    Do Until dbGrupoProduto.EOF
    Set dbProdutos = db.OpenRecordset("SELECT COD_PRO FROM Produto WHERE GRUPO_PRO = " & dbGrupoProduto!COD_GRUPO & " ORDER BY DES_PRO", dbOpenSnapshot)
    If dbProdutos.RecordCount > 0 Then dbProdutos.MoveLast: dbProdutos.MoveFirst
    .Nodes.Add , , , dbGrupoProduto!NOME_GRUPO & " - (" & dbProdutos.RecordCount & " )", 1
    X = .Nodes.Count
    Do Until dbProdutos.EOF
    .Nodes.Add X, tvwChild, , "[ " & dbProdutos!COD_PRO & " ]", 2
    TotalProd = TotalProd + 1
    dbProdutos.MoveNext
    Loop
    dbGrupoProduto.MoveNext
    Loop

    End With

    Set dbGrupoProduto = Nothing
    Set dbProdutos = Nothing
    DoEvents
    Screen.MousePointer = 0

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208
    hello,

    Fiirst of all I think you will have to test if you're clicking a child or not. The way I do it is to set a mark when it's a child.

    for example
    Code:
    Set treenode = TV.Nodes.Add("Root" & i, tvwChild, "longtext" & childcount, !maktx)
    If you set "child" of something before the name of the node you'll be able to test on it whenever someone clicks the treeview. In the example I set "longtext" before the actual name so I can test where the user clicked.

    I'm sure there are other ways too but this works fine for me.

  3. #3
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    You could do an if/then statement basically doing this:

    VB Code:
    1. Private Sub TreeView_NodeClick(ByVal CurNodeRun As Node)
    2. If CurNodeRun.Parent Is Nothing THen
    3.      'Do not run query
    4. Else
    5.      'Run Query
    6. End If
    7. End Sub

    Something like that? Let me know, Jeremy
    He who listens well, speaks well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width