Results 1 to 3 of 3

Thread: Tree view checkboxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Posts
    8

    Question Tree view checkboxes

    How can I cause a TreeView to have checkboxes only on the low-level nodes only (Only nodes with not children will have a checkbox

    Thanks

  2. #2
    Member Vahid's Avatar
    Join Date
    Aug 2002
    Location
    Iran
    Posts
    37
    You have to do some hard work, Dude! Try adding images of Unchecked Checkbox to desired nodes, then in changing the active node event check to see if Count property of Nodes property is zero. If it is, so this is your node, change image to other state - if it's checked change to unchecked and vice versa.

  3. #3
    New Member
    Join Date
    Sep 2002
    Location
    Swiss
    Posts
    1

    Treeview checkboxes

    Hi,

    I could do it with vb6 with the following code:

    Public Sub UnckeckNode(oTreeView As TreeView)

    ' Déclaration des variables
    Dim lngItem As Long

    lngItem = TreeView_GetSelection(oTreeView.hwnd)

    If lngItem Then

    Call SetTVItemStateImage(oTreeView.hwnd, lngItem)

    End If

    End Sub

    ' Retrieves the currently selected item.
    ' Returns the handle to the item if successful or 0 otherwise.
    Private Function TreeView_GetSelection(hwnd As Long) As Long

    TreeView_GetSelection = TreeView_GetNextItem(hwnd, 0, TVGN_CARET)

    End Function

    Private Function TreeView_GetNextItem(hwnd As Long, lngItem As Long, flag As Long) As Long

    TreeView_GetNextItem = SendMessage(hwnd, TVM_GETNEXTITEM, ByVal flag, ByVal lngItem)

    End Function
    ' Sets the index of the specified treeview item's state image.

    ' hwndTV - treeview's window handle
    ' lngItem - item's handle whose checkbox state is to be to set
    ' iState - value of the state image index

    ' Returns True if successful, returns False otherwise.
    Private Function SetTVItemStateImage(hwndTV As Long, _
    lngItem As Long) As Boolean

    Dim Tvi As TVITEM

    Tvi.mask = TVIF_HANDLE Or TVIF_STATE
    Tvi.lngItem = lngItem
    Tvi.stateMask = TVIS_STATEIMAGEMASK
    Tvi.state = 0

    SetTVItemStateImage = TreeView_SetItem(hwndTV, Tvi)

    End Function

    ' Sets some or all of a tree-view item's attributes.
    ' Old docs say returns zero if successful or - 1 otherwise.
    ' New docs say returns TRUE if successful, or FALSE otherwise
    Private Function TreeView_SetItem(hwnd As Long, pitem As TVITEM) As Boolean

    TreeView_SetItem = SendMessage(hwnd, TVM_SETITEM, 0, pitem)

    End Function

    But it doesn't work with vb.net. I don't know why ?
    Any Idea?

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