Solved

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

Posted on 2007-03-26
5
1,491 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
[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
  • 2
  • 2
5 Comments
 
LVL 52

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 52

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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…

635 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