?
Solved

CListBox and color

Posted on 2001-09-04
5
Medium Priority
?
404 Views
Last Modified: 2013-11-20
I use multicolumn list box to view data from SQL 7.0. I need to view just 2-3 column. I need to change colors of entrees to one of the columns. How can I do that.

Thanks  
0
Comment
Question by:yaAlex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6453012
I am of the opinion that you will have to draw the text yourself.  Using a ListView control might be easier, beause it supports Custom Draw (recent versions of the Common Control library and DLL required).  

Custom Draw would be easier, IMHO, because you do not have to do any of the drawing yourself, you just have to tell the control to use a certain color when drawing a certain column.

-=- James.
0
 

Author Comment

by:yaAlex
ID: 6454147

I can switch to the CListCtrl and CListView classes. But I need to be able to control the color of EACH idividual raw of one of the column. I would appreciate the code sample for that.  
0
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 300 total points
ID: 6455005
Take a look here: http://www.codeproject.com/listctrl/lvcustomdraw.asp

...In the case for handling "CDDS_ITEMPREPAINT", check the "iSubItem" (column) member of the NMLVCUSTOMDRAW structure.  That will be the column.  From there, you can determine what color to place in the "clrText" member of the NMLVCUSTOMDRAW structure and the "dwItemSpec" (row) member of the embedded NMCUSTOMDRAW structure.

Two notes:
   1: If the column order gets changed by the user (they drag and rearrange the columns), the internal column order is not changed, and your painting code will not have to check for that.
   2: Anytime you start messing around with colors, be sure to allow the user to select/change them, because you never know what the user's current color scheme may be.  At a minimum, make sure that the color you choose to paint the text with is not "near" (in colorspace) the background color of the control (COLOR_WINDOW).

-=- James.
0
 

Author Comment

by:yaAlex
ID: 6500017
Even though it was just a link, I accept your comment as an answer. Thank you for your help.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6502301
> Even though it was just a link, I accept your comment as an answer.

You asked for a code sample, you got one, as well as instructions for how to color each column.

> Thank you for your help.

NP.

-=- James.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question