Solved

Change Background Color in vb6 ListBox

Posted on 2014-03-08
3
1,801 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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