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

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

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

Post by Ovidiu Cucu » 24 Dec 2008, 18:43

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

Intrebare
Cum aflu numarul de coloane aflate intr-un control tip list-view (incapsulat intr-un obiect tip CListCtrl sau CListView) care are stilul "Report" (LVS_REPORT)?

Raspuns
Clasele MFC CListCtrl si CListView nu au nici o metoda care sa intoarca direct numarul de coloane.
Totusi, se poate gasi numarul de elemente al controlul header folosit de list-view, care este acelasi cu numarul de coloane.

Avem, de exemplu m_listCtrl de tipul CListCtrl

Code: Select all

   int nColumnCount = 0;
   CHeaderCtrl* pHeaderCtrl = m_listCtrl.GetHeaderCtrl();
   if(NULL != pHeaderCtrl)
   {
      nColumnCount = pHeaderCtrl->GetItemCount();
   }
Sau, intr-o clasa derivata din CListView

Code: Select all

int CMyListView::GetColumnCount()
{
   int nColumnCount = 0;
   CListCtrl& listCtrl = GetListCtrl();
   CHeaderCtrl* pHeaderCtrl = listCtrl.GetHeaderCtrl();
   if(NULL != pHeaderCtrl)
   {
      nColumnCount = pHeaderCtrl->GetItemCount();
   }
   return nColumnCount;
}

Next FAQ >>



Post Reply