CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 1999
    Posts
    51

    How to make CListCtrl selections have CListBox behavior??

    I'm using the report view style in a CListCtrl.
    I need it to operate like a CListBox in the way selections of items are made.

    The CListBox allows me to click on each item WITHOUT deselecting all the other items. I don't want the user to have to hold ctrl or shift down to maintain the previous selections in the CListCtrl.

    Also, I don't need the list control if there is another way I can have a report view. I have 3 columns of data to display.

    Is there any way to do this?




  2. #2
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: How to make CListCtrl selections have CListBox behavior??

    Use PreTranslateMessage() for the list control and individually turn the selection on and off

    Sally


  3. #3
    Join Date
    Apr 1999
    Posts
    51

    Re: How to make CListCtrl selections have CListBox behavior??

    I read up on PreTranslateMessage... I have a dialog bar in my MainFrame that contains the list control.
    Should I override PreTranslateMessage in MainFrame and just check which window handle the message occured in?

    After I handle things the way I want, should I just return non-zero so that any normal processing of the mouseclick will be skipped?

    Thanks,

    -V-



  4. #4
    Join Date
    Apr 1999
    Posts
    51

    I got it to work - thanks!

    If anyone wants the code, let me know.




  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: I got it to work - thanks!

    would be interesting to see what you did?

    sally


  6. #6
    Join Date
    Apr 1999
    Posts
    51

    Ok, here's the code


    BOOL CMainFrame::PreTranslateMessage( MSG* pMsg )
    {
    if ( pMsg->message == WM_LBUTTONDOWN )
    {
    CListCtrl* pLCtrl = (CListCtrl*) m_wndDialogBar.GetDlgItem( IDC_GRAPH_LIST ); // CListCtrl
    if ( pLCtrl->m_hWnd == pMsg->hwnd )
    {
    CPoint point( GET_X_LPARAM( pMsg->lParam ),
    GET_Y_LPARAM( pMsg->lParam ) );

    int index = pLCtrl->HitTest( point );

    ListItemInfo* pListItem;

    if ( index >= 0 )
    {
    pListItem = ( ListItemInfo* ) pLCtrl->GetItemData( index );
    CLineMonitorView* pView = GetActiveViewPtr();
    if ( ! pView )
    return TRUE;

    // if checkbox is selected
    if ( ListView_GetCheckState( pLCtrl->m_hWnd, index ) )
    {
    ListView_SetItemState ( pLCtrl->m_hWnd, index,
    UINT((int(0) + 1) << 12),
    LVIS_STATEIMAGEMASK);
    pLCtrl->SetItemState( index, ~LVIS_SELECTED, LVIS_SELECTED );

    // Tell the view that an overlay was selected or deselected, and send listItem
    pView->SendMessage( WM_APP_OVERLAY_CHANGED, 0, (LPARAM) pListItem );
    }
    else
    {
    ListView_SetItemState ( pLCtrl->m_hWnd, index,
    UINT((int(1) + 1) << 12),
    LVIS_STATEIMAGEMASK);
    pLCtrl->SetItemState( index, LVIS_SELECTED, LVIS_SELECTED );

    // Tell the view that an overlay was selected or deselected, and send listItem
    pView->SendMessage( WM_APP_OVERLAY_CHANGED, 1, (LPARAM) pListItem );
    }
    }

    return TRUE;
    }
    }
    return CMDIFrameWnd::PreTranslateMessage( pMsg );
    }





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