VC can set the CListCtrl class of cell color

Source: Internet
Author: User

One, Description:

CListCtrl control is easy to use, the drawback is not to set the color of cells, the author tries to extend the CListCtrl class, provides a function to set the color of cells,

Setitemcolor (int nitem, int nsubitem, COLORREF clrtext, Colorref clrbkgnd).

This class refers to the implementation of the sort function from Vckbase list control (author/Wang Jun), before using this class, please refer to the article first.

The example program works as shown in Figure one:

Figure One example program run effect chart

Second, the principle

When the cell is Listctrl, the NM_CUSTOMDRAW message is sent to the parent window, and as soon as the message is processed, we can customize the color we want. Please refer to the function in the source program: void CSortListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) Three, use the method//设置整行选择和带表格线模式
   m_MyListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  
   //设置列头
   m_MyListCtrl.SetHeadings(_T("ID,100;Name,100;BirthDate,100"));
  
   //添加项目
   m_MyListCtrl.AddItem(_T("1"),_T("栾义明"),_T("1979-07-25"));
   m_MyListCtrl.AddItem(_T("2"),_T("张伟"),_T("1982-03-26"));
  
   //设置单元格颜色。
   m_MyListCtrl.SetItemColor(0,1,RGB(255,0,0),RGB(0,255,0));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.