Thread: Listview selection change

  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273

    Listview selection change

    Hi. I've got a listview and I want to detect when a selection change has occurred. Just to learn how I've not been using resource files for this project and have been using CreateWindowEx for creating all the windows. Here's how I create the listview:
    Code:
      hwndArray[conferenceList] = 
        CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "",
          LVS_SHOWSELALWAYS | WS_BORDER | WS_CHILD | WS_VISIBLE | 
          LVS_REPORT | LVS_EX_GRIDLINES | LVS_SINGLESEL | LBS_NOTIFY,
          5, 5, 300, 280, hwnd, (HMENU)ID_CONFERENCELIST, g_hinst, NULL);
    And here's how I have been trying to detect selection changes:
    Code:
        case WM_NOTIFY: {
          NMHDR* nm = (NMHDR*) lParam;
    
          if ( nm->idFrom == ID_CONFERENCELIST && nm->code == LVN_ITEMCHANGED ) {
            LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
    
            if ( (pnmv->uChanged   & LVIF_STATE) &&
                  (pnmv->uNewState & LVIS_SELECTED) != 
                  (pnmv->uOldState & LVIS_SELECTED) ) {
              if (pnmv->uNewState & LVIS_SELECTED)
                MessageBox( 0,"Item has been selected",0,0);
              else
                MessageBox( 0,"Item has been deselected",0,0);
              // Specific item: pnmv->iItem
            }
          }
        }
    or
    Code:
        case WM_COMMAND: {
          // PROCESS SELECTION CHANGE MESSAGES
          switch( LOWORD(wParam) ) {
            case ID_CONFERENCELIST: {
              switch ( HIWORD(wParam) ) {
                case LBN_SELCHANGE: {
                  MessageBox(NULL, "Selection has changed", 0, 0 );
                } break;
              }
            }
          }
    But none of those two methods work. Am I doing something stupid here? I've been using this and this as references and these methods appear to work for them...

    'Not working' means the message boxes I've put up don't appear. It's also weird cause if I leave the WM_NOTIFY message in the code the main window that is created (not the conferenceList one) just flashes up and closes. No matter if I put in my style parameters or the ones from the aforementioned links. If notify is commented out the main window stays (feels like the ignore/get thing). The main window is created via.
    Code:
      hwnd = CreateWindowEx( 0, CLASS_NAME, "Conference catalog",
        WS_SYSMENU, (screenWidth-570)/2, (screenHeight-315)/2, 570, 315,
        0, 0, g_hinst, 0 );
    Thanks.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Yeah. It was something stupid alright. At the end of the notify case I didn't 'break;'.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 09:13 AM
  2. Replies: 6
    Last Post: 07-10-2006, 12:05 AM
  3. Listview??
    By SuperNewbie in forum C# Programming
    Replies: 4
    Last Post: 02-13-2003, 03:34 AM
  4. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

Tags for this Thread