Problems setting selection in listview window

This is a discussion on Problems setting selection in listview window within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to manually select a row in my listview using ListView_SetSelectionMark but nothing is happening. My code constantly updates ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Problems setting selection in listview window

    I'm trying to manually select a row in my listview using ListView_SetSelectionMark but nothing is happening. My code constantly updates the listview from a process queue, and to do this I simply delete all items and repopulate. Problem is, it appears that the selection value for the listview is staying, but the row doesn't highlight. Is there another function I need to call to actually highlight? Here is the relevant code:
    Code:
    int iIndex;
    iIndex=ListView_GetSelectionMark(hListView);
    
    ListView_DeleteAllItems(hListView);
    
    for (int i=0; i<processesQueue.size(); i++)
    {
    	lv.iItem=i;
    	ListView_InsertItem(hListView, &lv);
    	ListView_SetItemText(hListView, i, 0, processesQueue[i].status);
    	ListView_SetItemText(hListView, i, 1, processesQueue[i].processName);
    	ListView_SetItemText(hListView, i, 2, processesQueue[i].IMName);
    	ListView_SetItemText(hListView, i, 3, processesQueue[i].startTime);
    	ListView_SetItemText(hListView, i, 4, processesQueue[i].endTime);
    }
    
    ListView_SetSelectionMark(hListView, iIndex);
    Along the same lines, I want the user to be able to delete an item by pressing the delete key. Problem is, when the user clicks somewhere in the listview my main window loses focus and isn't able to trap the VK_DELETE message. Whats an easy way around this or do I have to declare a process for the listview child window?
    Last edited by PJYelton; 04-11-2005 at 10:16 PM. Reason: added another quick question

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by MSDN
    The selection mark is the item index from which a multiple selection starts. This macro does not affect the selection state of the item.
    You could try this instead:
    Code:
    ListView_SetItemState(hListView, iIndex, LVIS_SELECTED, LVIS_SELECTED);
    >> I want the user to be able to delete an item by pressing the delete key <<

    You could handle LVN_KEYDOWN, although action should usually occur on key-up.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    >>You could try this instead:

    Code:
    ListView_SetItemState(hListView, iIndex, LVIS_SELECTED, LVIS_SELECTED);<<

    Thanks, that worked!

    >>You could handle LVN_KEYDOWN, although action should usually occur on key-up.<<

    I'm not sure how to handle that exactly, I replaced WM_KEYDOWN in my main window proc to LVN_KEYDOWN but it didn't change anything. Am I missing something?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    It is passed through WM_NOTIFY. Your handler should look something like this:
    Code:
    case WM_NOTIFY:
    {
    	LPNMLVKEYDOWN plvkd = (LPNMLVKEYDOWN) lParam;
    
    	if (plvkd->hdr.hwndFrom == hListView   &&
                plvkd->hdr.code     == LVN_KEYDOWN &&
                plvkd->wVKey        == VK_DELETE)
    	{
    		/* Someone pressed the delete key. */
    	}
    }

  5. #5
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Not sure how many times I can keep thanking you, but thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  3. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 07:10 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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