List Views

This is a discussion on List Views within the Windows Programming forums, part of the Platform Specific Boards category; List Views are blowing my mind right now. Nothing shows up. The items are being added: A scroll bar appears, ...

  1. #1
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902

    List Views (Resolved)

    List Views are blowing my mind right now. Nothing shows up. The items are being added: A scroll bar appears, but no items show up.

    Here's the code:
    Code:
    HWND hwndWadList;
    
    void WadList_Update()
    {
    	LV_ITEM lvi;
    	DoomLump *lump;
    	unsigned int nlumps, x;
    	char text[10];
    
    	ListView_DeleteAllItems(hwndWadList);
    
    	ZeroMemory(&lvi, sizeof(LV_ITEM));
    	lvi.mask = LVIF_TEXT;
    
    	nlumps = wad_pwad->LumpCount();
    	//ListView_SetItemCount(hwndWadList, nlumps);
    
    	for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
    	{
    		lump = wad_pwad->GetLump(x);
    		strcpy(text, lump->GetName());
    		lvi.pszText = (char *) lump->GetName();
    		MessageBox(GetParent(hwndWadList), lump->GetName(), "", MB_OK);
    		lvi.iItem = x;
    		ListView_InsertItem(hwndWadList, &lvi);
    	}
    }
    The MessageBox() does display the name of the item, and it does show text. lump->GetName() is returning what it should. It's currently set to only do the first ten, because I didn't want bazillions of MessageBoxes. I know I shouldn't do the (char *) cast (it's casting it from const char *, doesn't really matter much) but it's only for debugging. I tried copying the data to a temporary buffer, text, and got the same result. (The rements are still visible...)

    Anyways, why is the pszText member not const? And why do I get a scrollbar and no items?

    Thanks!

    UPDATE: {1/1/06}
    Ok, I decided to check some error codes, always a good place to start. ListView_InsertItem is returning success (the index of the inserted item) So I added another loop outside and after my first for() loop to enumerate the names of all the items in the listbox. (Just to check.) It does so, and does it correctly! (I'm using ListView_GetItemText()...) But still the ListView remains a white box. (The scrollbar still appears if I shrink the window, so the ListView thinks there are items there... they're just not appearing.) Here is the revised convoluted debug ridden code I'm using: (Results haven't changed...)
    Code:
    void WadList_Update()
    {
    	LV_ITEM lvi;
    	DoomLump *lump;
    	unsigned int nlumps, x;
    	char text[10], err_buf[20], txtret[20];
    	int lvi_result;
    
    	ListView_DeleteAllItems(hwndWadList);
    
    	ZeroMemory(&lvi, sizeof(LV_ITEM));
    	lvi.mask = LVIF_TEXT;
    
    	nlumps = wad_pwad->LumpCount();
    	//ListView_SetItemCount(hwndWadList, nlumps);
    
    	for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
    	{
    		lump = wad_pwad->GetLump(x);
    		strcpy(text, lump->GetName());
    		lvi.pszText = text;
    		MessageBox(GetParent(hwndWadList), lump->GetName(), "", MB_OK);
    		lvi.iItem = x;
    		lvi_result = ListView_InsertItem(hwndWadList, &lvi);
    		sprintf(err_buf, "%d", lvi_result);
    		MessageBox(GetParent(hwndWadList), err_buf, "", MB_OK);
    	}
    
    	for(x = 0; x < (nlumps > 10 ? 10 : nlumps); x++)
    	{
    		ListView_GetItemText(hwndWadList, x, 0, txtret, 20);
    		MessageBox(GetParent(hwndWadList), txtret, "", MB_OK);
    	}
    }
    Sorry for the lengthy edit - thanks in advance for any insight. I'm at the end of my wit for now...

    Edit: If it helps, here's the ListView's creation:
    Code:
    hwndWadList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEWA, "", WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 100, 100, hwnd, NULL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    Edit: Resolved!
    Inspiration hit me. Despite giving it the LVS_NOCOLUMNHEADER style, it still has columns. (Duh, just no headers.) But I'd never specified the columns. Adding the needed code, things appears. I was looking at the wrong piece of code. (It'd kill them to document this? Or at least have the control have some default... like a blank column at 100px?) Thanks CBoard for at least letting me boil off some stress, problem solved!
    Last edited by Cactus_Hugger; 01-01-2006 at 02:06 PM. Reason: Update / more info
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21