当前位置: 动力学知识库 > 问答 > 编程问答 >

mfc - Multi selection will be lost when I clicked another column item in CListCtrl

问题描述:

  1. Please see the screen shot (which is a sample)
  2. I have a list view with 2 columns, the first one is "name" and the second one is "status"
  3. when I clicks the light bulb in second column, it will be changed between status 'on' and 'off'
  4. currently, I need to implement a multi select function. It is to use ctrl or shift to select several rows, and then click any one 'bulb' of them, and to switch the status of all selected items.

The problem is:

When I clicked the 'light bulb' the multi selected will be lost. It means when I uses API GetSelectedCount, it will return 0.

My Investigation:

When I clicked the 'light bulb', the event about item change will be triggered. and the OnItemChanged event will be triggered before OnClick event (that's why API GetSelectedCount will return 0 in event OnClock).

I wanted to cache the multi selected items in event OnItemChanged, but I failed because every item will trigger OnItemChanged event once.

for exmple: if I multi selected 3 items in the list view, and then click the 'light bulb' of the 3rd item, the event OnItemChanged will be triggered for 3 times, to notify the 3 items were un-selected. So, in OnClick event of (click light bulb), I don't know which items were selected in previous operations.

Furthermore, I still want to keep the multi selectionw after I click the 'light bulb'.

Any help will be much appreciated?

ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemChanged)

ON_NOTIFY_REFLECT_EX(NM_CLICK, OnClick)

void CListCtrl::OnItemChanged( NMHDR* pNMHDR, LRESULT* pResult ) {......}

BOOL CListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult) {......}

分享给朋友:
您可能感兴趣的文章:
随机阅读: