Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change Background Color in vb6 ListBox

Posted on 2014-03-08
3
Medium Priority
?
2,141 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

Independent Software Vendors: 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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