Solved

CListBox and color

Posted on 2001-09-04
5
370 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
  • 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 90
How to know only "File created" with EventLog 3 32
either24  challenge 19 90
zeroMAx challenge 20 87
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now