Solved

CListctrl problem: GetItem doesn't do anything

Posted on 1998-02-20
6
425 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now