5 Replies - 3679 Views - Last Post: 17 April 2012 - 10:07 AM Rate Topic: -----

#1 dreyk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-December 11

How do I color some items in a listBox?

Posted 17 April 2012 - 08:14 AM

Hello all who will come here and try to help me.
I'm done with my program, i just have some little problem. The problem it's about coloring the items in ListBox. I don't know how to color some items in ListBox, but with same background color that they are showed in TextBox. So i have a screenshoots here thats gonna explain my little problem:

Picture 1:
Posted Image
Picture 2:
Posted Image

Let me explain:
On picture 1 There is item that i get from RandomItem Button.Color it's depend on quality of item. For this example, i choose some Gloves with Green Background Color. So when i press on Take it, item go to my Invetnory and stay there while i don't use it, drop it or sell it. But i have problem with the background color of item when i took it in Inventory. So you can see on picture 1 that item got Green Background Color, and when i put it in my Inventory, (you can see in picture 2) there is no background color in ListBox. So My question it's, How i need to fix this code, to be able to take Text and Background Color together from the TextBox to ListBox. For now it's just Text. Here is the code that i used for transfering the Text from TextBox to the ListBox without color:

If TextBox1.Text = "" Then
            MsgBox("There is no item that you can take.")
        Else
            TextBox1.Text = ListBox1.Items.Add(a)
            TextBox4.Text = ListBox1.Items.Count
        End If



/update
reason: Pictures can't be loaded:

Picute 1:
Posted Image

Picutre 2:
Posted Image

This post has been edited by modi123_1: 17 April 2012 - 08:21 AM
Reason for edit:: fixing title to be more descriptive..


Is This A Good Question/Topic? 0
  • +

Replies To: How do I color some items in a listBox?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,369
  • Joined: 12-June 08

Re: How do I color some items in a listBox?

Posted 17 April 2012 - 08:19 AM

Moving to VB.NET
Was This Post Helpful? 1
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 838
  • Joined: 21-December 11

Re: How do I color some items in a listBox?

Posted 17 April 2012 - 09:18 AM

i think you can't change individually list box items. But you can do this with listview.
Was This Post Helpful? 0
  • +
  • -

#4 dreyk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-December 11

Re: How do I color some items in a listBox?

Posted 17 April 2012 - 09:42 AM

View Postsela007, on 17 April 2012 - 09:18 AM, said:

i think you can't change individually list box items. But you can do this with listview.


So you telling me that i can't do something like this? Because i have seen some programs on internet for other use, that can do that. So, can you just help me if there is some solution or maybe some other way?
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,369
  • Joined: 12-June 08

Re: How do I color some items in a listBox?

Posted 17 April 2012 - 10:03 AM

You would need to create a custom extend listview class and jack with the drawing options.. dictating what to draw, what color, and how.

Example here of changing the forecolor in an on draw.

http://msdn.microsof...x.drawitem.aspx
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2239
  • View blog
  • Posts: 9,409
  • Joined: 29-May 08

Re: How do I color some items in a listBox?

Posted 17 April 2012 - 10:07 AM

Here is an example (from my blog) of alternate line colouring on a listbox.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1