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..
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:
This will actually hold all the attributes for each item..
Next I changed the orginal posted code to the following:
Next I simply had to draw the dropdownlist on the form as follows:
The flow is easy to follow and does work..