Solved

Change Background Color in vb6 ListBox

Posted on 2014-03-08
3
1,687 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

14 Experts available now in Live!

Get 1:1 Help Now