Is there a change event for the list control?

Is there an equivalent event for LBN_SELCHANGEbut for a list?

+3
source share
4 answers

Use LVN_ODSTATECHANGEDfor an event.

The event parameter is a pointer to the type structure NMLVODSTATECHANGED. Use bit fields uNewStateand uOldStateto determine which ones are selection changes (because there are other changes). You are looking for a flag LVIS_SELECTED.

+1
source

But do not trust ListView_GetSelectionMark () in this event handler - get the selected item with

ListView_GetNextItem(list_hwnd, -1, LVNI_SELECTED);

+1
source

LVN_ITEMCHANGED.

NOTIFY_HANDLER(IDC_FILELIST, LVN_ITEMCHANGED, OnListViewItemChanged)

LRESULT CMainDlg::OnListViewItemChanged(int, LPNMHDR hdr, BOOL&) {
    NMLISTVIEW* lpStateChange = reinterpret_cast<NMLISTVIEW*>(hdr);
    if ((lpStateChange->uNewState ^  lpStateChange->uOldState) & LVIS_SELECTED) {
        // Do something
    }
    return 0;
}
+1
 case WM_NOTIFY:
  NMLISTVIEW *VAL_notify = (NMLISTVIEW*)VII_lParam;
  if(VAL_notify->hdr.code == LVN_ITEMCHANGED && VAL_notify->hdr.idFrom == IDC_SOMECONTROL  && (VAL_notify->uNewState & LVIS_SELECTED))
      {
      // Use VAL_notify->iItem as the new selected item
      }
0

Source: https://habr.com/ru/post/1702135/


All Articles