Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CListBox and color

Posted on 2001-09-04
5
Medium Priority
?
410 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

609 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