Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

770 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