Change background color of individual rows


Changing the color of a single row is achieved in essentially the same way as changing the background color of the entire control. See 'Change background color'.

Instead of using the same color for all rows, use a row specific color. If you want to be able to add any color to any row then you would have to track this information in some data structure. In the code below we simply highlight the alternate rows with yellow. This code belongs in the DrawItem() function. See 'Selection highlighting of entire row' for more details.

	// Draw the background color
	if( bHighlight )
	{
		pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

		pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
	}
	else
	{
		CRect rcClient, rcRow = rcItem;
		GetClientRect(&rcClient);
		rcRow.right = rcClient.right;

		pDC->FillRect(rcRow, &CBrush(nItem%2 ? ::GetSysColor(COLOR_WINDOW) :
	 					RGB(255,255,0)));
	}

 



Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Driven by the need for greater productivity and lower costs, enterprises around the globe are moving their applications to the cloud. This application note describes networking challenges that cloud-enabled enterprises face in today's digital economy, and the top reasons why intelligent optical networks are becoming critical to their success, with a direct impact on productivity and the ability to compete for long-term business success.

  • As your content grows, it can be challenging to define the proper rules, regulations and policies that govern that content and ensure proper protection and compliance. Entrusting your content to Box – the only secure, modern content platform in the cloud – is the right first step. The next step is to evaluate your retention, disposition and defensible discovery needs and to establish the proper buy-in to satisfy all your needs. In this Information Governance webinar, learn how Box Governance can add …

Most Popular Programming Stories

More for Developers

RSS Feeds

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