Getting the number of columns in the report view


To get the number of columns in the list view control, we first get a pointer to the header control and then use the header control to query the number of columns it has.
CHeaderCtrl* pHeader = (CHeaderCtrl*) m_listctrl.GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();
This works even when the listview control has the LVS_NOCOLUMNHEADER style. It also works if the control is not in the report view.
 



Comments

  • A valid pointer to CHeaderCtrl object

    Posted by Legacy on 11/26/2003 12:00am

    Originally posted by: Mirko

    Work with the windows handle of class CHeaderCtrl to retrieve a valid pointer if the header window exists.
    // The pointer to my list control.
    extern CListCtrl* pMyListControl;

    // ThePointer to my header control
    CHeaderCtrl* pHeader = NULL;

    HWND hwndList = 0;
    HWND hwndHeader = 0;

    hwndList = pMyListControl->GetSafeHwnd();
    hwndHeader = ListView_GetHeader(hwndList); //macro use
    pHeader = (CHeaderCtrl*)FromHandle(hwndHeader);
    if(pHeader)
    int nColumnCount = pHeader->GetItemCount();

    Reply
  • Use GetHeaderCtrl

    Posted by Legacy on 11/06/2001 12:00am

    Originally posted by: Joost van den Boom

    Instead of using "m_listctrl.GetDlgItem(0)" use "m_listctrl.GetHeaderCtrl()" then it works fine!

    Joost

    Reply
  • Wrong number of columns.

    Posted by Legacy on 05/17/2000 12:00am

    Originally posted by: Alon

    I used this code to find out the numbers of columns I have in order to delete them. I got wrong number and I made the deletion in that way:
    
    

    while(m_ListCtrl.DeleteColumn(0) != 0);

    In that way I didn't have any problem!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The world of data storage is changing around us as organizations continue to seek ways by which they can leverage cloud-based services. However, simply shifting everything to the public cloud is generally neither desirable nor feasible, so organizations are struggling with finding ways that they can leverage the public cloud and its outcomes where it makes sense and leave everything else on-premises. The Gorilla Guide lays out the key questions and considerations you need to think through in building your …

  • The relentless march of end user organizations toward cloud services continues, despite long-standing fears about information security, the lack of visibility into cloud provider security controls, and the shortcomings of controls available to those who utilize cloud services. And while more and more security-as-a-service (SaaS) solutions and application programming interfaces (APIs) are becoming available, many cloud service providers just aren't moving fast enough to address today's enterprise needs. Read …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date