Listbox color ??? 500 easy points!

I have a listbox that has 3 or 4 different colors, How can I have a message box or a string display what the color of the selected item in the listbox is...This question is urgent and worth 500 points!
LVL 2
juravichAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Bob LearnedCommented:
I am assuming that you have an owner-drawn listbox displaying the colors.

Is this a valid assumption?  If so, then how are you accomplishing this?

Bob
0
 
juravichAuthor Commented:
This is how im displaying the colors. I'm afraid this is the only way that i know how to do it.



Private Sub CumulativeBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles CumulativeBox.DrawItem
        Dim materialInside As String
        Dim materialboolean As Boolean

        e.DrawBackground()

        materialInside = CumulativeBox.Items(e.Index)

        Dim Br As Brush
        If (CumulativeBox.Items(e.Index)) = vbTab & "Action Changes" Or (CumulativeBox.Items(e.Index)) = vbTab & "Code Changes" Then
            Br = Brushes.DarkGray
        ElseIf materialInside.StartsWith(vbTab & vbTab) Then
            Br = Brushes.Red
        Else
            Br = Brushes.RoyalBlue    
        End If

        e.Graphics.DrawString(CumulativeBox.Items(e.Index), e.Font, Br, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        e.DrawFocusRectangle()

    End Sub
0
 
Bob LearnedCommented:
(1) Create an array of colors:

     Private itemColors() As Color

(2) After filling the list box:

     Redim itemColors(CumulativeBox.Items.Count - 1)

(3) Add a tooltip component to the form.

(4) When drawing each item:

         If (CumulativeBox.Items(e.Index)) = vbTab & "Action Changes" Or (CumulativeBox.Items(e.Index)) = vbTab & "Code Changes" Then
            Br = Brushes.DarkGray
            itemColors(e.Index) = Color.DarkGray
        ElseIf materialInside.StartsWith(vbTab & vbTab) Then
            Br = Brushes.Red
            itemColors(e.Index) = Color.Red
        Else
            Br = Brushes.RoyalBlue    
            itemColors(e.Index) = Color.RoyalBlue
        End If

       Me.Tooltip1.SetTooltip(CumulativeBox, itemColors(e.Index).Name)

Bob
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
juravichAuthor Commented:
I'm finding it somewhat hard to understand your answer...I'm sorry

Let me explain a little further what i have...

I have the listbox (cumulativebox), in this listbox there are a bunch of different items, all of different type. Each type has been given a color by using the drawing item above. I just need a way to find out what the type of item is (by using the color).

i.e. Severe = red

I want to find out what is severe by seeing if the color is red.

Thanks alot!
0
 
Bob LearnedCommented:
Do you want this information as a user interface item, or a debug item?

All I was trying to do is come up with a solution to keep track of the colors for each item in an type-specific Color Array, so that you can query it.


Bob
0
 
juravichAuthor Commented:
ohh ok, well im gonna give your previous solution a try and see what i can find out.

I am using this information as a user interface item.
0
 
juravichAuthor Commented:
I thought about your suggestion and used the logic to create something very similar to your code that fits my needs perfectly. Thank you very much for the insight!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.