Solved

CListBox and color

Posted on 2001-09-04
5
393 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
repeatSeparator  java  challenge 13 58
List out all word 7 338
Work with App store 7 96
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

730 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