Solved

Bold or colour for an individual word in a listbox for VBA/VB6

Posted on 2007-03-26
5
1,455 Views
Last Modified: 2012-06-27
Hi Experts,

I have a form with a listbox that uses the standard VBA listbox control.  

Private Sub UserForm_Initialize()
ListBox1.ListStyle = 1
ListBox1.MultiSelect = fmMultiSelectSingle
ListBox1.AddItem "I want to highlight the 6 numbers"
ListBox1.AddItem "Perhaps 1 could use bold for digits "
ListBox1.AddItem "I want 2 know if you could use a colour as well"
ListBox1.Selected(0) = True
ListBox1.ListIndex = -1
End Sub

This gives three lines of text in the listbox and a set of radio buttons to choose between them.

The text appears in regular, sans serif typeface.  Which is what I want.  However, I really want to put one word in bold / different colour in each line.  In this case, I want to highlight the digits, ie "6" in the first line, "1" in the second line or "2" in the third line.  

The only way to do that with the standard control seems to be placing "*" around either side of the word.  But that looks bad.  It really needs to be bold or italics or colour or something to really bring that individual word away from the rest of the sentence.

Is there any way to do this?  Is there any other kind of control for VBA / VB6 where I can keep my list and the radio buttons and also have the highlight of an individaul word in the sentence?

Thanks in advance,

PatternNut
0
Comment
Question by:PatternNut
  • 2
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 18792074
Not too sure but first thought that you cannot bold a row in a Listbox control, perhaps you can try use a ListView control instead.
0
 

Author Comment

by:PatternNut
ID: 18792114
Hi Ryan,

Thanks for this... but I don't want to bold a row.  I want to bold an individual word within a row.  Do you think listview might be able to do that?

Cheers,

PatternNut
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 125 total points
ID: 18792358
Hi,

I got no aware of any control can customize only certain part of its content that present in a row format. The only thing I'm thinking is using HTML control, where you can customize perfectly to what you want, but I think this is not what you want..
0
 
LVL 22

Accepted Solution

by:
danaseaman earned 375 total points
ID: 18793318
You would need to  create and ownerdraw listbox that accepts basic Html for items and you will need a Html parser to do this.

To do this yourself would be take several days even for an experienced programmer.

OwnerDraw ListBox with source code:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=62442&lngWId=1

Here are 2 Html parsers with source code:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=30318&lngWId=1
http://www.vbthunder.com/software/cooltips/index.php

This is a commercial product that supports Html but it looks more like a WebBrowserControl:
http://hotlist-html-listbox-activex-control.eztools-software.qarchive.org/
0
 

Author Comment

by:PatternNut
ID: 18818288
Hi both,

Obviously this isn't the answer that I wanted to hear... but it is an answer and it is right.  And Danaseaman, the links you sent are really helpful.  I really appreciate the help that the two of you provided on this one and even if it's not what I wanted to hear, it's really good you took the time to write it.  Big, big help for me.

Thanks,

PatternNut
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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

863 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