CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    92

    Columns in list control

    How do you get the column count of a list control?


  2. #2

    Re: Columns in list control

    For MSVC 6:

    // How many columns are there?
    int MyListCtrl::GetColumnCount() const
    {
    // One of the few examples of when this cast is okay. (Microsoft forgot
    // to supply a const CListCtrl::GetHeaderCtrl() - doh!)
    CHeaderCtrl* pHeader = const_cast<MyListCtrl*> (this)->GetHeaderCtrl();
    ASSERT_VALID(pHeader);

    return pHeader ? pHeader->GetItemCount() : -1;
    }


    For MSVC5, this is the best we can do:

    // Does the sent column exist?
    BOOL MyListCtrl::IsColumn(int nCol) const
    {
    _ASSERTE(0 <= nCol);

    LV_COLUMN lvc;
    ::ZeroMemory(&lvc, sizeof(lvc));
    lvc.mask = LVCF_WIDTH;

    return -1 < nCol && GetColumn(nCol, &lvc);
    }



    LA Leonard - http://www.DefinitiveSolutions.com

  3. #3
    Join Date
    May 1999
    Posts
    92

    Re: Columns in list control

    I thank you for your response, but I am still using vc4 for the meantime. I hope you have an example for this version?


  4. #4

    Re: Columns in list control

    The one for MSVC5 should work for MSVC4, I think...

    LA Leonard - http://www.DefinitiveSolutions.com

  5. #5
    Join Date
    May 1999
    Posts
    92

    Re: Columns in list control

    I tried it and it did the trick. Thanks!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured