Problem showing item in TreeView

This is a discussion on Problem showing item in TreeView within the Windows Programming forums, part of the Platform Specific Boards category; My application uses a TreeView control and I'm having trouble showing an item. The program compiles perfectly fine, but when ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Problem showing item in TreeView

    My application uses a TreeView control and I'm having trouble showing an item. The program compiles perfectly fine, but when I run it, there isn't the item in the TreeView like I thought I programmed in. Any ideas? Here's the code where it adds an element to the TreeView (or at least that I thought would add an element):
    Code:
    void InitTree(void)
    {
        TV_INSERTSTRUCT  tvs;
        TV_ITEM          tvi;
    
        tvs.hInsertAfter = TVI_LAST;
        tvi.mask = TVIF_TEXT;
    
        tvi.pszText = TEXT("test");
        tvs.hParent = TVI_ROOT;
        tvs.item = tvi;
        hTreeItem = TreeView_InsertItem(hTreeWndCtrl, &tvs);
        hTreeCurrent = hTreeItem;
    }
    Any ideas why I can't get my element to show up? What do I need to change/do?

    Thanks!
    1978 Silver Anniversary Corvette

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Any ideas? Do you need to see more code? Please help.
    1978 Silver Anniversary Corvette

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I could pretend that I knew this off the top of my head, but the truth is that I spent thirty seconds reading the documentation.

    TVIF_TEXT
    The pszText and cchTextMax members are valid.
    Code:
    void InitTree(void)
    {
        TVINSERTSTRUCT tvs = { 0 };
    
        tvs.hInsertAfter    = TVI_LAST;
        tvs.hParent         = TVI_ROOT;
    
        tvs.item.mask       = TVIF_TEXT;
        tvs.item.pszText    = TEXT("test");
        tvs.item.cchTextMax = lstrlen(tvs.item.pszText);
    
        hTreeItem    = TreeView_InsertItem(hTreeWndCtrl, &tvs);
        hTreeCurrent = hTreeItem;
    }

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Nope, didn't work. Any other ideas? I'm getting desparate now.
    1978 Silver Anniversary Corvette

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I have no idea. Have you checked that hTreeWndCtrl is valid? Called InitCommonControls? I'm sure someone here must have working treeview code. By the way, my last post may have been wrong, you may not need cchTextMax in this situation, although the documentation is unclear.

    The MSDN sample shows:
    Code:
        tvi.pszText = lpszItem; 
        tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);
    which is very wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 11:52 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. Need help with program.
    By olgirl4life in forum C++ Programming
    Replies: 3
    Last Post: 12-11-2006, 10:06 PM
  4. Programmatically creating nodes in a treeview problem
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 10-12-2006, 02:41 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21