I have a listbox, which contains about 12 items. I want to have it to
display different colors, depending on its value. Is it possible to do
that? I know how to change the color and the font of the whole listbox.
But don't know how to achieve that for each of the listed item.

Any help is appreciated.

Tony

Re: Different color for different item in ListBox by Igor

Igor
Fri Nov 21 13:21:05 CST 2003

"Tony Hu" <bytj@yahoo.com> wrote in message
news:e$JlcLGsDHA.3496@TK2MSFTNGP11.phx.gbl...
> I have a listbox, which contains about 12 items. I want to have it
to
> display different colors, depending on its value. Is it possible to
do
> that?

Make the listbox owner-drawn. Set LBS_OWNERDRAWFIXED or
LBS_OWNERDRAWVARIABLE style, handle WM_DRAWITEM message.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: Different color for different item in ListBox by Tony

Tony
Fri Nov 21 15:37:41 CST 2003

Do appreciate your help, Ignor. You do help me a lot when a lot of VC
features are still new to me.

Tony

"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:%23fZVPTGsDHA.3456@tk2msftngp13.phx.gbl...
> "Tony Hu" <bytj@yahoo.com> wrote in message
> news:e$JlcLGsDHA.3496@TK2MSFTNGP11.phx.gbl...
> > I have a listbox, which contains about 12 items. I want to have it
> to
> > display different colors, depending on its value. Is it possible to
> do
> > that?
>
> Make the listbox owner-drawn. Set LBS_OWNERDRAWFIXED or
> LBS_OWNERDRAWVARIABLE style, handle WM_DRAWITEM message.
> --
> With best wishes,
> Igor Tandetnik
>
> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken
>
>



Re: Different color for different item in ListBox by Michael

Michael
Fri Nov 21 16:15:15 CST 2003

Tony Hu wrote:
: Do appreciate your help, Ignor. You do help me a lot when a lot of
: VC features are still new to me.
:
: Tony

It is not a special VC feature but native windows API, so u also can use
this in any other programming language which will let you access the window
proc.

Btw, most controls work like the listbox, even ownerdraw menus are created
this way. The MSDN library is a good reference for these. Should be located
under Platform SDK -> ... -> Windows Controls (or sth like that).

Regards
'Mike



Re: Different color for different item in ListBox by Tony

Tony
Fri Nov 21 17:42:50 CST 2003

Thanks, Michael. I'll check that out.

Tony

"Michael Maier" <michael.maier1@rwth-aachen.de> wrote in message
news:bpm2pj$cvd$1@nets3.rz.RWTH-Aachen.DE...
> Tony Hu wrote:
> : Do appreciate your help, Ignor. You do help me a lot when a lot of
> : VC features are still new to me.
> :
> : Tony
>
> It is not a special VC feature but native windows API, so u also can use
> this in any other programming language which will let you access the
window
> proc.
>
> Btw, most controls work like the listbox, even ownerdraw menus are created
> this way. The MSDN library is a good reference for these. Should be
located
> under Platform SDK -> ... -> Windows Controls (or sth like that).
>
> Regards
> 'Mike
>
>



Re: Different color for different item in ListBox by Anders

Anders
Mon Nov 24 02:37:31 CST 2003

On Fri, 21 Nov 2003 14:08:32 -0500, Tony Hu wrote:

> I have a listbox, which contains about 12 items. I want to have it to
> display different colors, depending on its value. Is it possible to do
> that? I know how to change the color and the font of the whole listbox.
> But don't know how to achieve that for each of the listed item.
>
A very neat way is to use Custom-Draw. You need to use version 4.70 or
later, but 'most' people have it already (comes with IE 4 or later)

A very good article is found at CodeProject:

Neat Stuff to do in List Controls Using Custom Draw
By Michael Dunn
http://www.codeproject.com/listctrl/lvcustomdraw.asp

Best Wishes!
// Anders