Thread: api listview - finding subitem clicked

  1. #1
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    api listview - finding subitem clicked

    I've got a listview using no column header, report, single select, and full row select styles. The column data is occupied by a single character and is 20px wide; each row can contain similar values, so searching for a specified value isn't feasible.

    Is there a function to determine which subitem a user has clicked on? I can find the selected row, but I'm just not sure how I'd go about finding the column. ListView_GetSelectedColumn seemed promising, but it always returns 0.

    I'm looking to find both the row and col by index pos.

    Code:
    case WM_NOTIFY :
    
    	if(((LPNMHDR)lParam)->code == NM_CLICK) {
    		
    		int index = SendMessage(hndListV, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
                    // need help finding the subitem
    				
           }
    
    break;
    Any ideas would be greatly appreciated.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    This might help. As it mentions the structure has members for item, subitem and where the click was. That and/or LVM_SUBITEMHITTEST should get you somewhere.

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Thank you for the reply; I sure appreciate your time.

    I tried it out but couldn't get what I was looking for. I'm still trying to learn the basics, so I probably goofed it up somewhere. I did come up with something using a chimp approach that *appears* to work.

    Code:
    if(((LPNMHDR)lParam)->code == NM_CLICK) {
    				
        int index = SendMessage(hndListV, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
        POINT pt = { 0 };
        LVITEM lvi;
    
        GetCursorPos(&pt);
        ScreenToClient(hndListV, &pt);
    
        ZeroMemory(&lvi, sizeof(LVITEM));
    
        lvi.iItem = index;       
        lvi.iSubItem = pt.x / 14;  // 14 is the cx member of the LVCOLUMN structure
        ...
    }

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Something like...

    Code:
    NMITEMACTIVATE  NMItem = {0};
    int row = -1, column = -1;
    
    if(((LPNMHDR)lParam)->code == NM_CLICK) 
    { 
         NMItem = (LPNMITEMACTIVATE) lParam;
         //row clicked is the item member 
         row = NMItem.iItem;
         //column clicked is subitem
         column = NMItem.iSubItem;
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    novacain, thank you immensely; it does exactly what I wanted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is this "subItem = citem.substr(12,3);"possible?
    By airesore in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2011, 02:02 PM
  2. Sending Clicked message
    By cgod in forum C# Programming
    Replies: 0
    Last Post: 08-24-2005, 02:13 AM
  3. PHP: how to get most clicked link?
    By alphaoide in forum Tech Board
    Replies: 2
    Last Post: 07-07-2004, 03:18 PM
  4. How to tell what was clicked on? (OpenGL)
    By napkin111 in forum Game Programming
    Replies: 4
    Last Post: 07-01-2003, 12:36 PM
  5. when clicked load file
    By andrewjf9 in forum Windows Programming
    Replies: 5
    Last Post: 11-20-2002, 03:46 AM