• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

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!
0
juravich
Asked:
juravich
  • 4
  • 3
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now