Results 1 to 7 of 7

Thread: Stumper - Treeview Control Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Post

    what i want to do is create a child
    then set that child to bold.

    nodX = TreeView1.Nodes.Add("r", tvwChild, Addto2, Addto2)

    nodx.child.bold?


    any help will be appricated


  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Unfortunately, TreeView doesn't have a direct way of doing that, BUT...there is a workaround to achieve what you want. Here is an example:

    Code:
    Private Const TVGN_NEXT                As Long = &H1
    Private Const TVGN_CARET               As Long = &H9
    Private Type TV_ITEM
       mask As Long
       hItem As Long
       state As Long
       stateMask As Long
       pszText As String
       cchTextMax As Long
       iImage As Long
       iSelectedImage As Long
       cChildren As Long
       lParam As Long
    End Type
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const TV_FIRST As Long = &H1100
    Private Const TVM_GETNEXTITEM As Long = (TV_FIRST + 10)
    Private Const TVM_GETITEM As Long = (TV_FIRST + 12)
    Private Const TVM_SETITEM As Long = (TV_FIRST + 13)
    Private Const TVM_SETBKCOLOR As Long = (TV_FIRST + 29)
    Private Const TVM_SETTEXTCOLOR As Long = (TV_FIRST + 30)
    Private Const TVM_GETBKCOLOR As Long = (TV_FIRST + 31)
    Private Const TVM_GETTEXTCOLOR As Long = (TV_FIRST + 32)
    Private Const TVIF_STATE As Long = &H8
    Private Const TVIS_BOLD  As Long = &H10
    
    
    Private Sub Command2_Click()
        Dim xNode As Node
        Dim xChild As Node
        Dim TVI As TV_ITEM
        Dim lItemHwnd As Long
        Dim lTreeHwnd As Long
       
        
        With TreeView1
            Set xNode = .Nodes.Add(, , , "Parent")
            Set xChild = .Nodes.Add(xNode, tvwChild, , "Child")
            xChild.EnsureVisible
        End With
        
        xChild.Selected = True
        lTreeHwnd = TreeView1.hwnd
        lItemHwnd = SendMessage(lTreeHwnd, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0&)
        
       If lItemHwnd > 0 Then
          With TVI
             .hItem = lItemHwnd
             .mask = TVIF_STATE
             .stateMask = TVIS_BOLD
              Call SendMessage(lTreeHwnd, TVM_GETITEM, 0&, TVI)
             .state = TVIS_BOLD
          End With
          Call SendMessage(lTreeHwnd, TVM_SETITEM, 0&, TVI)
       End If
    End Sub
    This will add a Parent and a Child nodes, then it will make the Child node Bold.

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

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

    [This message has been edited by Serge (edited 02-21-2000).]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Post

    Thanks serge didn't know the call rutine..

    they should incorperate a function for this control for runtime effects like this...

    Thanks for your help.


    [This message has been edited by BHostmeyer (edited 02-21-2000).]

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Post

    Is there anyway to change the line color as well.

    maybe with the TVM_SETTEXTCOLOR ?

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    It's not that simple, but it is possible. Instead of writing the code into the post, here is the Link to the exact answer for your question.

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

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    P.S All given code was for people who doesn't have VB6. For VB6 it is very easy to do without any hassle.

    Code:
    Private Sub Command1_Click()
        Dim xNode As Node
        Dim xChild As Node
        
        
        With TreeView1
            Set xNode = .Nodes.Add(, , , "Parent")
            Set xChild = .Nodes.Add(xNode, tvwChild, , "Child")
            xChild.EnsureVisible
        End With
        
        With xChild
            .Bold = True
            .ForeColor = vbRed
        End With
    End Sub
    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Post

    LOL now you tell me..

    I used the childx.forecolor and it worked so i figured the other code was for vb5..

    Thanks for the help

    Brooke

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