Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:35:41+00:00 2026-06-02T07:35:41+00:00

This is a WinForms Application in VB. In my application I am trying to

  • 0

This is a WinForms Application in VB. In my application I am trying to make it easier for the user to pick out items in a list quickly based on the items text color.. So I am trying to assign the color to each item using a select case statement as below… The problem is that I am getting an error saying “Public member ‘Attributes’ on type ‘String’ not found.” VB flags the lines with the Attribute.Add param with this error.. Here is the code that I currently have…

   For Each u In _units
                _counter += 1
                u_lookupNumber_box.Items.Add((Convert.ToString(u.UnitId)) + " - " + (Convert.ToString(u.perMonthCost)))
                Select Case u.occupied
                    Case Is = 0
                        u_lookupNumber_box.Items(_counter - 1).Attributes.add("style", "color: Yellow")
                    Case Is = 1
                        u_lookupNumber_box.Items(_counter - 1).attributes.add("style", "color: Green")
                    Case Is = 2
                        u_lookupNumber_box.Items(_counter - 1).attributes.add("style", "color: Red")
                    Case Is = 3
                        u_lookupNumber_box.Items(_counter - 1).attributes.add("style", "color: Blue")
                    Case Is = 4
                        u_lookupNumber_box.Items(_counter - 1).attributes.add("style", "color: Orange")
                    Case Is = 5
                        u_lookupNumber_box.Items(_counter - 1).attributes.add("style", "color: Purple")
                End Select
            Next

Any ideas why I am getting this error?? I did notice that when I did the .attributes part when I hit “.” and typed “att” it did not appear in the intelisense box in vb.. Which makes me think I need to assign the name “attributes” somehow to the dropdownbox first.. Thanks for any and all help…

It should be noted that u_lookupNumber_box is the name of the drop down box on my form..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:35:43+00:00Added an answer on June 2, 2026 at 7:35 am

    Ok so a long bread crumb trail of searches and a bit of trial and error and I got it to work fully… Because of constant processing of drawItem event arg I am not too happy with it but other than that it works as expected… First I set the DrawMode property of the dropdown to OwnerDrawFixed. Then created a structure in my form class as such:

    Public Structure ColoredUnitItem
        Dim text As String
        Dim color As Color
        Dim bold As Boolean
        Public Overrides Function ToString() As String
            Return text
        End Function
    End Structure
    

    This will actually hold all the attributes for each item..

    Next I changed the orginal posted code to the following:

    For Each u In _units
                    _counter += 1
                    Dim myItem As New ColoredUnitItem
                    With myItem
                        .text = (Convert.ToString(u.UnitId)) + " - " + (Convert.ToString(u.perMonthCost))
                        Select Case u.occupied
                            Case Is = 0
                                .color = Color.Yellow
                            Case Is = 1
                                .color = Color.Green
                            Case Is = 2
                                .color = Color.Red
                            Case Is = 3
                                .color = Color.Blue
                            Case Is = 4
                                .color = Color.Orange
                            Case Is = 5
                                .color = Color.Purple
                        End Select
                    End With
                    u_lookupNumber_box.Items.Add(myItem)
                Next
    

    Next I simply had to draw the dropdownlist on the form as follows:

    Private Sub uLookUpNumberBox_Draw(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles u_lookupNumber_box.DrawItem
        e.DrawBackground()
        If Not e.Index = -1 Then
            Dim myItem As ColoredUnitItem = DirectCast(u_lookupNumber_box.Items(e.Index), ColoredUnitItem)
            Dim FontToUse As Font = e.Font
            If myItem.bold Then
                FontToUse = New Font(e.Font, FontStyle.Bold)
            End If
            e.Graphics.DrawString(myItem.text, FontToUse, New SolidBrush(myItem.color), e.Bounds)
            e.DrawFocusRectangle()
        End If
    End Sub
    

    The flow is easy to follow and does work..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement this pattern in my WinForms application (I don't like it,
I'm tweaking a WinForms application. This application has a Form that contains a PropertyGrid
I have a WinForms application with a bunch of third party references. This makes
I am using Segoe UI for my winforms application. On XP, this font doesn't
In a winforms application, I'm using a RichTextBox and I'm trying to reduce the
Im trying to integrate a toolwindow in a Winforms application, it will be a
I am trying to use System.Net.WebClient in a WinForms application to upload a file
In order to make a convenient UI for an .Net 2.0 Winforms application I
I'm trying to integrate a new WPF control into an existing WinForms application and
I have some TreeView's in my winform application. I am trying to make mass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.