Solved

ListView question.....

Posted on 2001-08-28
2
526 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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 30
MSVCR80.dll crash 2 138
best sources to up-to-date in C++? 8 78
How to convert Structure to vector of byte and vice versa 5 12
  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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

813 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

14 Experts available now in Live!

Get 1:1 Help Now