Page 1 of 1

[WinAPI] Cum aflu numarul de coloane intr-un list-view?

Posted: 24 Dec 2008, 18:27
by Ovidiu Cucu
Intrebare
Cum aflu numarul de coloane aflate intr-un control tip list-view care are stilul "Report" (LVS_REPORT)?

Raspuns
Nu exista o functie sau un mesaj care sa intoarca direct numarul de coloane pe care le are un list-view. Totusi, il putem afla din numarul de elemente pe care le are controlul header folosit de list-view.

Code: Select all

   int nColumnCount = 0; 
   HWND hWndHeaderCtrl = (HWND)::SendMessage(hWndListCtrl, LVM_GETHEADER, 0, 0);
   if(NULL != hWndHeaderCtrl)
   {
      nColumnCount = (int)::SendMessage(hWndHeaderCtrl, HDM_GETITEMCOUNT, 0, 0);
   }
In mod similar dar un pic mai comod putem folosi macro-urile ListView_GetHeader si Header_GetItemCount definite in commctrl.h.

Code: Select all

   int nColumnCount = 0; 
   HWND hWndHeaderCtrl = ListView_GetHeader(hWndListCtrl);
   if(NULL != hWndHeaderCtrl)
   {
      nColumnCount = Header_GetItemCount(hWndHeaderCtrl);
   }

<< Back to Windows API Index