dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 33

Thread: [RESOLVED] Coloring header row of CListCtrl C++

  1. #1
    Join Date
    Oct 2019
    Posts
    36

    [RESOLVED] Coloring header row of CListCtrl C++

    I have class MyClistCtrl derived from CListCtrl. I want to do two things:
    1. Show only horizontal grid lines (I tried LVS_EX_GRIDLINES ,but this displays both horizontal as well as Vertical grid lines)

    2. Change background color of header row,it is of gray color(system color),i want it to be white.I read several post and codes but nothing helped so please if anyone from Scratch can tell me with Code how to achieve that

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    I have class MyClistCtrl derived from CListCtrl. I want to do two things:
    1. Show only horizontal grid lines (I tried LVS_EX_GRIDLINES ,but this displays both horizontal as well as Vertical grid lines)
    But the Vertical grid lines are drawn by default. isn't it?
    Victor Nijegorodov

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    ... Change background color of header row,it is of gray color(system color),i want it to be white.I read several post and codes but nothing helped so please if anyone from Scratch can tell me with Code how to achieve that
    Have a look at this thread.
    Last edited by VictorN; October 9th, 2019 at 02:15 PM.
    Victor Nijegorodov

  4. #4
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    No no no..confusion.
    You are right vertical grid lines are drawn by default but my requirement is i only want horizontal grid lines not both horizontal and vertical grid lines..

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    ... but my requirement is i only want horizontal grid lines not both horizontal and vertical grid lines..
    You may want to create your own user defined control.
    Victor Nijegorodov

  6. #6
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    Means there is nothing like LVS_ something which can only draw horizontal gridlines,if so please can you help me with code snippet of user defined control you are talking about which can help me in achieving this.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    Means there is nothing like LVS_ something which can only draw horizontal gridlines,if so please can you help me with code snippet of user defined control you are talking about which can help me in achieving this.
    Sorry! I never needed such a control... So try to google for that.
    Victor Nijegorodov

  8. #8
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    I did googled but no success...nothing worth found

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    I did googled but no success...nothing worth found
    sorry...
    Victor Nijegorodov

  10. #10
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    Can you please tell how and where WM_DRAWITEM should be called...and where is m_ HeaderCtrl declared?

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    ...and where is m_ HeaderCtrl declared?
    See:
    CListCtrl::GetHeaderCtrl
    Header Control and List Control
    Victor Nijegorodov

  12. #12
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    What about WM_DRAWITEM

  13. #13
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    And plz help me with correct code because i have read all this CListCtrl::GetHeaderCtrl and Header Control stuff but couldn't able to implement it in a successful way
    That's why asking for urgent help

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,543

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    And plz help me with correct code because i have read all this CListCtrl::GetHeaderCtrl and Header Control stuff but couldn't able to implement it in a successful way
    That's why asking for urgent help
    post your code
    Victor Nijegorodov

  15. #15
    Join Date
    Oct 2019
    Posts
    36

    Re: Coloring header row of CListCtrl C++

    class IEHeaderCtrl : public CHeaderCtrl { // Construction public: IEHeaderCtrl(); // Generated message map functions protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    DECLARE_MESSAGE_MAP()
    }

    Code for IEHeaderCtrl.cpp

    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP

    void IEHeaderCtrl::
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDITEM hdi; CBrush brush(RGB(255, 0, 0)); CString csBuffer; CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM)); hdi.mask = HDI_TEXT; LPTSTR pBuf = csBuffer.GetBufferSetLength(MAX_PATH); hdi.mask = HDI_TEXT; hdi.pszText = pBuf; hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer(); CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); pDC->FillRect(rectFrame, &brush); pDC->SetTextColor(RGB(255, 255, 255)); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach();
    }

    /*code for Myformview.cpp where my listctrl is embedded:*/

    void MyFormView :: OnInitiUpdate()
    {
    IEHeaderCtrl m_HeaderCtrl;
    CHeaderCtrl* pHeader = NULL; pHeader=m_List.GetHeaderCtrl(); VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd)); HDITEM hdItem; hdItem.mask = HDI_FORMAT;
    }

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)