Solved

ListView question.....

Posted on 2001-08-28
2
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 150 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

729 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