Jabberwocky
Jabberwocky

Reputation: 50775

How to get the number of columns in a list control

I need to get the number of columns in a list control in report mode.

Right now I'm sending a LVM_GETCOLUMN with increasing column number until SendMessage returns FALSE:

int col;
for (col = 0;; col++)
{ 
  LVCOLUMN Column;
  Column.mask = LVCF_WIDTH;
  if (!::SendMessage(hWnd, LVM_GETCOLUMN, col, (LPARAM)Column)
    break;
}

But this is rather awkward.

Upvotes: 6

Views: 5430

Answers (1)

Werner Henze
Werner Henze

Reputation: 16726

You can retrieve the number of columns from the header control of the list control.

HWND hWndHdr = (HWND)::SendMessage(hWnd, LVM_GETHEADER, 0, 0);
int count = (int)::SendMessage(hWndHdr, HDM_GETITEMCOUNT, 0, 0L);

Upvotes: 20

Related Questions