Color ListBox VB
mich8569
Posted messages
68
Status
Member
-
almoal Posted messages 64 Status Member -
almoal Posted messages 64 Status Member -
I have a question in VB:
I have a ListBox with several items in it.
Is it possible to display some items in one color and others in another color?
Name of the ListBox: list
I’ve seen the ForeColor property which I use like this:
list.ForeColor = Color_in_hex
But the problem is that it changes the color of all items in the ListBox. Is there a way to change the color of only some items?
Thanks for the help
I have a ListBox with several items in it.
Is it possible to display some items in one color and others in another color?
Name of the ListBox: list
I’ve seen the ForeColor property which I use like this:
list.ForeColor = Color_in_hex
But the problem is that it changes the color of all items in the ListBox. Is there a way to change the color of only some items?
Thanks for the help
4 answers
-
I managed to sort it out thanks to conditional formatting.
Notably:
Activated = 1
ListBox1.FormatConditions.Add acExpression, acEqual, Activated = 1
then later in the code with a condition:
ListBox1.FormatConditions(0).BackColor = vbRed
This only colors it if it is selected, however, but with a condition.
Final validation is done by pressing Enter.
I’ll still take a look at your code.
Thanks :) -
to add colors in your listbox, you need to create a subclassing with the API: SetWindowLong, then you create your Windows loop and you handle the messages sent by Windows to your application, you can search for examples on the site:
http://www.vbfrance.com. -
go look over there: https://codes-sources.commentcamarche.net/
-
Maybe conditional formatting could help you?
With conditions like a field value, an expression or a value activated.
;)