?
Solved

Change Background Color in vb6 ListBox

Posted on 2014-03-08
3
Medium Priority
?
2,056 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1000 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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