Announcement

Collapse
No announcement yet.

Image removal from TreeView not working?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Image removal from TreeView not working?

    The TreeView Insert Item code lines below are supposed to prevent images from showing alongside the TreeView data items. Despite using the 0 image value, to indicate no image, my code still shows icons.

    Has anyone else had this problem?

    By experimenting, I noticed that it's always the first icon in the imagelist - as though the 0 is used for the first image, rather than 1, as is stated in the Help file.

    I tried -1 and 999 (arbitrarily large). -1 still shows an image. 999 does not show an image, but leaves a gap where an image would be is #999 existed.

    If I completely remove the imagelist, then no images are shown. But I'm looking to pick and choose which items get images. Athough, it appears that if any item has an image, even those without will have a gap displayed where the image would have gone. Not as clean looking as I wanted.

    The pbr file is http://www.garybeene.com/files/pb-test.pbr is you need it.

    Code:
     #Compile Exe
     #Include "win32api.inc"
     #Include "commctrl.inc"
     #Resource "pb-test.pbr"
     Global hDlg As Dword, hLst As Dword, hItem As Dword, hTemp As Dword
     Function PBMain() As Long
        Dialog New Pixels, 0, "TreeView Test",200,200,200,250, _
                                        %WS_OverlappedWindow, 0 To hDlg
        'create control
        Control Add Treeview, hDlg, 100, "", 10,10,175,225   '225
    
        'create imagelist  w,h,depth,size
        ImageList New Icon 16,16,32,3 To hLst
        ImageList Add Icon hLst, "x"
        ImageList Add Icon hLst, "y"
        ImageList Add Icon hLst, "z"
    
        'attach imagelist
        Treeview Set ImageList hdlg, 100, hLst
    
        '                                 %TVI_FIRST  %TVI_LAST   %TVI_SORT
        'add items  hdlg, id&, hPrnt, hIAftr, image&, selimage&, txt$ to hItem
        Treeview Insert Item hDlg, 100, 0, %TVI_Last, 0,0,"One" To hItem
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"One-1" To hTemp
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"One-2" To hTemp
    
        Treeview Insert Item hDlg, 100, 0, %TVI_Last, 0,0,"Two" To hItem
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"Two-1" To hTemp
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"Two-2" To hTemp
    
        Treeview Insert Item hDlg, 100, 0, %TVI_Last, 0,0,"Three" To hItem
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"Three-1" To hTemp
           Treeview Insert Item hDlg, 100, hItem, %TVI_Last, 0,0,"Three-2" To hTemp
    
    
        Dialog Show Modal hDlg Call DlgProc
     End Function
    
     CallBack Function DlgProc() As Long
        If Cb.Msg = %WM_Notify And Cb.NmId = 100 And _
                          Cb.NmCode = %TVN_SelChanged Then
           MsgBox "Selected!"
        End If
    Last edited by Gary Beene; 7 Feb 2009, 10:17 AM.

  • #2
    Gary, I think that you get space reserved for the image once you use tvm_setimagelist. I have seen code where the developer cunningly uses a line image which appears to extend the treeview's own line through the image space, though I can't recall where.

    Comment


    • #3
      I tried -1 and 999 (arbitrarily large). -1 still shows an image. 999 does not show an image,
      but leaves a gap where an image would be is #999 existed.
      In SDK, -1 removes the image.

      If you do not want a gap, you will have to use the state imagelist. A quick glance at the Help
      File seems to indicate that you cannot set a state imagelist using DDT.

      A treeview control can have two imagelists, a normal imagelist and a state imagelist. You will have
      to use SDK code to set the state imagelist. For example,
      Code:
       
        SendMessage hWndChild, TVM_SETIMAGELIST, %TVSIL_STATE, hImageList
      This item will have an image
      Code:
              szItem = "Nutmegs"
              ttvins.item.itemex.mask           = %TVIF_TEXT OR %TVIF_STATE
              ttvins.item.itemex.stateMask      = %TVIS_STATEIMAGEMASK
              ttvins.item.itemex.state          = IndexToStateImageMask(%STATE_FORWARD)
              ttvins.item.itemex.pszText        = VARPTR(szItem)
              ttvins.hParent                    = @phItem[0]
              ttvins.hInsertAfter               = %TVI_LAST
              @phItem[1] = SendMessage(hWndChild, %TVM_INSERTITEM, 0, BYVAL VARPTR(ttvins))
      This one will not have an image
      Code:
              szItem = "Bananas"
              ttvins.item.itemex.mask           = %TVIF_TEXT
              ttvins.item.itemex.pszText        = VARPTR(szItem)
              ttvins.hParent                    = @phItem[0]
              ttvins.hInsertAfter               = %TVI_LAST
              @phItem[1] = SendMessage(hWndChild, %TVM_INSERTITEM, 0, BYVAL VARPTR(ttvins))
      State images are usually 16x16 pixels, but they can be any size.
      Dominic Mitchell
      Phoenix Visual Designer
      http://www.phnxthunder.com

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎