Solved

color and bold in listview row

Posted on 2004-09-08
7
2,034 Views
Last Modified: 2013-12-25
hi all,

i hav a form that having a listview to display data from database.

wat i need is to make the certain row of the listview to appear in certain color or bold in certain conditions.

for e.g
select case x
case x = 1
    'listview row in blue
case x = 2
    'listview row in red
case x = 3
    'listview row in bold
end select

n etc.can this be done in listview?

thx in advance.

rgds,
daniel
0
Comment
Question by:daniellyh
  • 3
  • 2
7 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 12012692
Try like:

Private Sub Command1_Click()
    ListView1.ListItems.Clear
    For i = 1 To 30
        ListView1.ListItems.Add i, , "item " & i
        Select Case i Mod 3
        Case 0
            ListView1.ListItems(i).ForeColor = vbRed
            ListView1.ListItems(i).Bold = True
        Case 1
            ListView1.ListItems(i).ForeColor = vbBlue
            ListView1.ListItems(i).Bold = True
        Case 2
            ListView1.ListItems(i).ForeColor = vbBlack
        End Select
    Next i
End Sub

Try customize above example and apply your logic there.

Hope this helps
0
 
LVL 15

Expert Comment

by:ameba
ID: 12014900
Or, if row has more than one column:

Private Sub Form_Click()
    Dim k As Integer, itmx As ListItem
   
    Set itmx = Me.ListView1.ListItems(2)
    With itmx
        .ForeColor = vbRed   ' first column
        .Bold = True
        For k = 1 To .ListSubItems.Count ' other columns
            .ListSubItems(k).ForeColor = vbBlue
            .ListSubItems(k).Bold = True
        Next
    End With
End Sub
0
 
LVL 1

Author Comment

by:daniellyh
ID: 12022757
hi all,
thx for ur help n let me some times to try on it..thx.

rgds,
daniel
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:daniellyh
ID: 12332980
hi ameba,
i've try n it seem like not working when i set the listview to lvwreport?

rgds,
daniel
0
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 12333074
It should work in VB6 (or VB5) with component "Microsoft Windows Common Controls 6 (SP4)".  If you have older project which uses version 5, you can upgrade to version 6, or use APIs for version 5.
0
 
LVL 1

Author Comment

by:daniellyh
ID: 12335525
hi,
ok let me spend some times trying it. i will be at outstation this few days.

rgds,
daniel
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 code to programmatically convert pdf to excel 21 92
Problem to skip loop 6 57
Export Data to Different .csv Files 26 105
Automatic Email Reminder 4 38
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

803 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