Solved

CListBox and color

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 67
WinWaitActive parameters 12 31
string initialization in java 11 103
Making an alias 7 54
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 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

10 Experts available now in Live!

Get 1:1 Help Now