Solved

highlight new items in listbox

Posted on 2004-04-05
8
246 Views
Last Modified: 2012-05-04
Is it possible to set the text format to bold for individual rows in a list box?

I am trying to recreate something like Outlook in an Access form, and so I want new entries in the list box to appear in bold, until they are clicked on (like new emails are in bold in Outlook). Is this possible?
0
Comment
Question by:mlittler
  • 3
  • 3
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 10756119
Not sure if that is possible, because I think the font properties apply to all entries in a listbox

Have you thought of using the FlexGrid, its more powerful because of its formatting features
or maybe the listview control (reference "Microsoft Widows Common Controls" )
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 10756131
create a listview control on your form

and here is some sample code which populates it

    Dim li As ListItem
    With lstView
        .View = lvwReport
        .HideColumnHeaders = True
        .ColumnHeaders.Add , , "Column1"
        .ListItems.Add , "Row1", "Row1"
        .ListItems.Add , "Row2", "Row2"
        .ListItems.Add , "Row3", "Row3"
       
    End With
   
    For Each li In lstView.ListItems
        If li.Text = "Row2" Then
            li.ForeColor = vbRed
            li.Bold = True
        End If
    Next

'Note a selected row is put in bold and coloured Red

0
 
LVL 12

Expert Comment

by:nexusnation
ID: 10758640
try modifying the code above to find the selected item and unbold it.

    For Each li In lstView.ListItems
        If li.Text = "Row2" Then
        li.Bold = False
    Next


            li.ForeColor = vbRed
            li.Bold = True
        End If
    Next
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:nexusnation
ID: 10758641
try modifying the code above to find the selected item and unbold it.

    For Each li In lstView.ListItems
        If li.Text = "Row2" Then
        li.Bold = False
    Next


            li.ForeColor = vbRed
            li.Bold = True
        End If
    Next
0
 
LVL 12

Expert Comment

by:nexusnation
ID: 10758653
oops, that was a mispost.

   For Each li In lstView.ListItems
        If li.Text = Me.lstView.ItemData(Me.lstView.Selected(x)) Then
           li.Bold = False
           Exit For
        End If
    Next

I don't know (or even think) that this will work because I used some properties/collections that I don't think that are for list view, but I'm not sure.

Andrew
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10758688
I created a sample form and put that code in, it seems to work for me
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

21 Experts available now in Live!

Get 1:1 Help Now