Solved

CListctrl problem: GetItem doesn't do anything

Posted on 1998-02-20
6
418 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

19 Experts available now in Live!

Get 1:1 Help Now