Solved

Change Background Color in vb6 ListBox

Posted on 2014-03-08
3
1,749 Views
Last Modified: 2014-03-08
I have a list box that draws events and dates from a database.  How can I highlight only events that are on the current date?  Actually I don't care if they are highlighted or bold or different text color...just want them to stand out.
0
Comment
Question by:Bob Schneider
3 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 250 total points
ID: 39914662
You can't.  The foreground and background colours and the font settings are the same for all items in the VB6 listbox.

There is a third party listbox that does have different settings for each item available here:
http://mb-extended-listbox-control-c-program-ad.software.informer.com/

Here is some sample code:
Option Explicit

Private Sub Form_Load()
    Dim i As Integer
    
    For i = 1 To 6
        ListEx1.AddItem CStr(i)
    Next i
    
    For i = 1 To 6 Step 2
        ListEx1.Items(i).BackColor = vbRed
    Next i

End Sub

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 39914685
I confirm that "out of the box", you cannot set that.
using subclassing, you can use windows api to do this, nevertheless:
http://www.freevbcode.com/ShowCode.asp?ID=2835
risk: subclassing may make your project less stable while debugging ...
I had used above without general issues when rolled out, though.

you may take the listview instead of a listbox, there you can put your items with different colors and/or bold etc, without having to use subclassing or third-party code.
http://msdn.microsoft.com/en-us/library/ms172636%28v=vs.90%29.aspx
0
 

Author Closing Comment

by:Bob Schneider
ID: 39914770
Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now