Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ListView question.....

Posted on 2001-08-28
2
Medium Priority
?
567 Views
Last Modified: 2008-03-03
LVITEM item;
ZeroMemory(&item, sizeof(item));
item.mask = LVIF_TEXT;
item.iItem = ListView_GetItemCount(GetDlgItem(hWnd, IDC_LIST1));
item.pszText = data;
ListView_InsertItem(GetDlgItem(hWnd, IDC_LIST1), &item);


Ok, that is what I have.  And yes, the hWnd is entered right, I know this.. because I tested it with a MessageBox.  now...  data, DOES have text in it.  The following line works:

MessageBox(hWnd,data,"Weeeeee",MB_OK);

It shows up on the dialog box, with the correct data that I want to place in the ListView.  The list view IS called IDC_LIST1,  but this doesn't work!!!  ListView_InsertItem does not work... and I do not know why.  Can anyone assist me please!  Thank you.
0
Comment
Question by:police1
2 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 600 total points
ID: 6435177
ListView has some fitcher:
your data must be allocated and used only for
for this item(not used for other).
Next is my code: exist really only one(but very
important) difference:

int TMyListView::AddItem(char *szText, int iItem)
{
  LV_ITEM lvi;
    // Initialize LV_ITEM members that are common to all items.
  lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  lvi.state = 0;
  lvi.stateMask = 0;
  lvi.pszText = LPSTR_TEXTCALLBACK;   // app. maintains text
  lvi.iImage = 0;                     // image list index

        // item label and the text of each subitem.
   char *pItem = strdup(szText); //this is difference!!!!

        // Initialize item-specific LV_ITEM members.
   lvi.iItem = iItem;
   lvi.iSubItem = 0;
   lvi.lParam = (LPARAM) pItem;    // item data

        // Add the item.
  return ::SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) (const LV_ITEM FAR *)&lvi);
}

0
 

Author Comment

by:police1
ID: 6435184
Cool, thanks a lot!  :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

782 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