CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    181

    Question SelectedItem Icon differs with declaration.

    I use such code for add items to CTreeView
    tvInsert.item.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
    tvInsert.item.iImage = 1;
    tvInsert.item.iSelectedImage = 1;
    But when I run program in selection field I see other icon - #0, which differs with common state image...
    What wrong in my actions?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: SelectedItem Icon differs with declaration.

    Could you show some more lines? Because it is not clear what you do this this tvInsert object.
    And, BTW, how many icons does the imagelist have?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2012
    Posts
    181

    Question Re: SelectedItem Icon differs with declaration.

    VictorN,
    3
    Such I create ImageList:
    CImageList *IL = new CImageList();
    IL->Create(16,16,true,0,1);
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON3));
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON4));
    pView->GetTreeCtrl().SetImageList(IL, TVSIL_NORMAL);

    Such create item in CTreeView():
    void CDirView::OnInitialUpdate()
    {
    CTreeView::OnInitialUpdate();
    start = true;
    CTreeCtrl &TreeCtrl = GetTreeCtrl();
    TVINSERTSTRUCT tvInsert;
    tvInsert.hParent = NULL;
    tvInsert.hInsertAfter = NULL;
    tvInsert.item.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
    tvInsert.item.iImage = 1;
    tvInsert.item.iSelectedImage = 1;
    tvInsert.item.pszText = _T("C:");
    HTREEITEM hRoot1 = TreeCtrl.InsertItem(&tvInsert);
    tvInsert.item.pszText = _T("C:\\dipol\\iso");
    HTREEITEM hRoot2 = TreeCtrl.InsertItem(&tvInsert);
    tvInsert.item.pszText = _T("C:\\dipol\\apt");
    HTREEITEM hRoot3 = TreeCtrl.InsertItem(&tvInsert);
    tvInsert.hParent = hRoot1;
    tvInsert.item.pszText = _T("t");
    TreeCtrl.InsertItem(&tvInsert);
    /* tvInsert.hParent = hRoot2;

    Icons differs!!...

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: SelectedItem Icon differs with declaration.

    IL->Create(16,16,true,0,1);
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON3));
    IL->Add(AfxGetApp()->LoadIcon(IDI_ICON4));
    pView->GetTreeCtrl().SetImageList(IL, TVSIL_NORMAL);
    I'd look in this direction. 16x16 is a small icon size, while TVSIL_NORMAL is used for large icons.
    Best regards,
    Igor

Tags for this Thread

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

Featured