CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Location
    Italy
    Posts
    47

    ClistCtrl - Get DoubleClick Row data

    Hi, I've lurked a bit in previous forum but I'm not sure yet.

    If ,in a Report view list control ,I want to edit the data of a row after I've DoubleClicked it with left mouse button, how can i do ?

    To edit data I would like to make appear a dialog Box that accept the right fields listened.

    many thanks.
    ciao
    Lord Hol Napult
    ----------------------------------------------------
    Freeware Game : No One Shoots Forever
    Builder's Heaven (Cobol/Easytrieve): BH Homepage
    LHN Digital & Informatic Blog: NOSF BLOG

  2. #2
    Join Date
    Mar 2004
    Posts
    382

    Re: ClistCtrl - Get DoubleClick Row data

    First, override the list views NM_DBLCLK command. In the message handler you need to hit test to see if an item on the list was clicked, and if it was, you need to determine which item. Below is the code which does that. This is almost exactly from "Programming windows with MFC"

    In the following code, the list view is in a dialog and m_list is a CListView member of the dialog class. If you are using a Doc/View architecture, it shouldn't be difficult to make this code work for that project as well.

    Code:
    void CMyDialog::OnDoubleClickList(NMHDR* pNMHDR, LRESULT* pResult) 
    {
        DWORD dwPos = ::GetMessagePos ();
        CPoint point ((int) LOWORD (dwPos), (int) HIWORD (dwPos));
        m_list.ScreenToClient (&point);
    
        int nIndex;
        if ((nIndex = m_list.HitTest (point)) != -1) {
            // If you are in this if block, that means an item on the list
            //   was chosen and nIndex is the index of the selected item
            //   from the list.
    
            // Do whatever you want to do with the selected item
            return;
        }
        *pResult = 0;
    }
    Good luck.

  3. #3
    Join Date
    Jan 2006
    Location
    Italy
    Posts
    47

    Re: ClistCtrl - Get DoubleClick Row data

    Many Thanks! It works Fine.

    But how can I get the Column where I am in addition to the Row...
    ciao
    Lord Hol Napult
    ----------------------------------------------------
    Freeware Game : No One Shoots Forever
    Builder's Heaven (Cobol/Easytrieve): BH Homepage
    LHN Digital & Informatic Blog: NOSF BLOG

  4. #4
    Join Date
    Mar 2004
    Posts
    382

    Re: ClistCtrl - Get DoubleClick Row data

    That's straightforward.
    Code:
    // nIndex is the row index from the list.
    // The second argument is the column index. It's 0 based so 0 is for the 1st
    //   column and 1 is for the second column, etc...
    CString strCol1, strCol2;
    strCol1 = m_list.GetItemText (nIndex, 0); // Get the 1st column data for the row nIndex
    strCol2 = m_list.GetItemText (nIndex, 1); // Get the 2nd column data for row nIndex

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ClistCtrl - Get DoubleClick Row data

    For another example, check out this post. This thread has a sample where each list view item is represented by a class object (via the SetItemDataPtr). Also, this is an example of a virtual list-view, which allows efficient display of large lists (see msdn for more on virtual list-views). It also shows how to modify item data and (if I remember correctly), has code to determine the column clicked on.

    Arjay

  6. #6
    Join Date
    Aug 2012
    Posts
    9

    Cool Re: ClistCtrl - Get DoubleClick Row data

    Thank you very much..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured