Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CListctrl problem: GetItem doesn't do anything

Posted on 1998-02-20
6
Medium Priority
?
466 Views
Last Modified: 2013-11-20
   I have a CListCtrl in a dialog box.  I want to be able to retrieve the image index.  I have tried something like this.  //Row contains the selected row //m_List is the list member of the Dialog box
    LV_ITEM Item;
    ZeroMemory(&Item, sizof(LV_ITEM));
    Item.mask=LVIF_IMAGE;
    Item.iItem=Row;
    Item.iSubItem=0;
    m_List.GetItem(&Item);

The problem is nothing changes.  The Image index remains 0.  Even when I have set masks for everything nothing is changed.  I can't get the name through this method.  However GetItemText(Row, 0) works fine for getting the Text.
0
Comment
Question by:JChapman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:dr_funfrock
ID: 1316443

 The Image index is the index into the imagelist associated with this listctrl. The reason you get zero is because this row uses image 0 from the imagelist.
0
 

Author Comment

by:JChapman
ID: 1316444
No, that's not the problem.  I have two types files and folders.  This is for an ftp client.  I don't want to have to go and search the ftp site again to see if the selected item is a folder, which I tried and sort of worked.  But anyways I have three items in the imagelist.  Only the first two are of concern to me.  And every time it comes out 0, even if I set that item to 1.  THAT'S THE PROBLEM.  Its not that it actually is 0.  Even when I set the mask for the name of the item it comes back as null.  So what's the problem?
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316445
  (First, are you sure your m_List member is bound to the correct List Control?)

   Try changing the "iImage" member to a value other than 0, before calling GetItem(...), just to make sure that it is actually being changed by the control.

   You also might want to use the "lParam" member of LV_ITEM to hold a flag telling you what kind of file this item is (Text, ZIP, GZ, TAR, Unknown Binary, Directory, SLink, HLink, etc.).

   For getting the Item's text, make sure that you specify the LVIF_TEXT flag, and that you place a pointer to a buffer in the "pszText" member, and specify the buffer size in "cchTextMax".

-=- James.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JChapman
ID: 1316446
   Well this is strange, I went and deleted my code and typed it back in, and now I get the correct iImage value.  However the text still doesn't work.  Thanks for the responces though!
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316447
_What_ text doesn't work?  What are you talking about?

.B ekiM


0
 

Accepted Solution

by:
ingee earned 100 total points
ID: 1316448
To get item's text, you should have a buffer.
Following code may be help for you. (I wish...)
:>

void SomeClass::SomeFunc()
{
   int idItem = m_ctrList.GetNextItem(-1, LVNI_ALL|LVNI_FOCUSED);

   LV_ITEM lvi;
   const int nBufSize=100;               //max buf size
   _TCHAR szBuf[nBufSize + 1];           //text buffer

   memset(&lvi, 0, sizeof(LV_ITEM));
   lvi.mask = LVIF_TEXT | LVIF_IMAGE;
   lvi.iItem = idItem;
   lvi.pszText = szBuf;                  //you should to do!
   lvi.cchTextMax = nBufSize;            //you should to do!
   m_ctrList.GetItem(&lvi);
      
   TRACE("item id == %d\n", lvi.iItem);
   TRACE("item text == %s\n", lvi.pszText);
   TRACE("item image == %d\n", lvi.iImage);
}

0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question