Welcome to Dream.In.Code
Become a VB Expert!

Join 137,228 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,889 people online right now. Registration is fast and FREE... Join Now!




Listbox Items

 
Reply to this topicStart new topic

Listbox Items, Making different items in a listbox different colors

danfwald
6 Mar, 2007 - 10:09 AM
Post #1

New D.I.C Head
*

Joined: 25 Jul, 2006
Posts: 11


My Contributions
Is it possible to make different items in a listbox different colors depending on certain program variables? The listbox.forecolor property makes all items in the collection the same color. I want to do the following:

if x > 0 then listbox.forecolor = color1 : listbox.items.add(x.tostring)
if x < 0 then listbox.forecolor = color2 : listbox.items.add(x.tostring)


User is offlineProfile CardPM
+Quote Post

KeyWiz
RE: Listbox Items
7 Mar, 2007 - 10:49 AM
Post #2

D.I.C Regular
Group Icon

Joined: 26 Oct, 2006
Posts: 428


Dream Kudos: 125
My Contributions
You can create a custom CLASS which inherits the LISTBOX Class
then you provide OverRides for each line, to change the text color.
Then Call the new Class - whatever you name it (ColorListBox) and create an instance of your new class object.
You will then have to define the new Line Color properties based on your new Class

User is offlineProfile CardPM
+Quote Post

danfwald
RE: Listbox Items
23 Mar, 2007 - 03:43 PM
Post #3

New D.I.C Head
*

Joined: 25 Jul, 2006
Posts: 11


My Contributions
QUOTE(KeyWiz @ 7 Mar, 2007 - 11:49 AM) *

You can create a custom CLASS which inherits the LISTBOX Class
then you provide OverRides for each line, to change the text color.
Then Call the new Class - whatever you name it (ColorListBox) and create an instance of your new class object.
You will then have to define the new Line Color properties based on your new Class



I have been playing around with your suggestion, but getting nowhere. Would you please write a few lines of code showing the overrides in the new class that inherits the listbox class.

Thanks
dan
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:01PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month