Click to See Complete Forum and Search --> : How to make CListCtrl selections have CListBox behavior??


Volkan
May 25th, 1999, 02:22 PM
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?

sally
May 25th, 1999, 05:56 PM
Use PreTranslateMessage() for the list control and individually turn the selection on and off

Sally

Sally
May 25th, 1999, 05:56 PM
Use PreTranslateMessage() for the list control and individually turn the selection on and off

Sally

Volkan
May 25th, 1999, 06:09 PM
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-

Volkan
May 25th, 1999, 07:02 PM
If anyone wants the code, let me know.

sally
May 27th, 1999, 06:26 AM
would be interesting to see what you did?

sally

Sally
May 27th, 1999, 06:26 AM
would be interesting to see what you did?

sally

Volkan
May 27th, 1999, 10:34 AM
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 );
}