CListctrl problem: GetItem doesn't do anything

   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.
JChapmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dr_funfrockCommented:

 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
JChapmanAuthor Commented:
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
jtwine100697Commented:
  (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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

JChapmanAuthor Commented:
   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
mikeblasCommented:
_What_ text doesn't work?  What are you talking about?

.B ekiM


0
ingeeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.