Solved

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

Posted on 2007-03-26
5
1,464 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 50

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 50

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

809 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