|
-
May 25th, 1999, 02:22 PM
#1
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?
-
May 25th, 1999, 05:56 PM
#2
Re: How to make CListCtrl selections have CListBox behavior??
Use PreTranslateMessage() for the list control and individually turn the selection on and off
Sally
-
May 25th, 1999, 06:09 PM
#3
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-
-
May 25th, 1999, 07:02 PM
#4
I got it to work - thanks!
If anyone wants the code, let me know.
-
May 27th, 1999, 06:26 AM
#5
Re: I got it to work - thanks!
would be interesting to see what you did?
sally
-
May 27th, 1999, 10:34 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|