Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

CListctrl problem: GetItem doesn't do anything

Posted on 1998-02-20
6
Medium Priority
?
475 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

580 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