Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

coloring rows in Listview

Status
Not open for further replies.

DonS100

Programmer
Dec 4, 2001
104
0
0
US
Hello, I have an Access 97 application that uses listview controls. I want to highlight certain rows with different colors. Is this possible?

Thanks

Don
 
No

Hallo,

Or at least probably not. You could you make the listbox transparent and put coloured labels behind, but even then you'd need to know which entry was displayed at the top of the list box, which I don't think you can.

Could you make a continuous subform to look like a list box?

- Frink
 
Hi,
I was waiting for this thread if anyone can help me also.
I think it is not possible in Access. There are samples I have seen in VB6 that used picturebox control to show alternate line color in ListView. There is a free activex download from Visual Creations
Check this thread for conditional formating in ListView

thread705-837321
regards

Zameer Abdulla
 
To conditionally format a listview control try this.

' Using ADO recordsets

dim lv as object
dim itm as mscomctlib.listitem
dim rs as adodb.recordset ' ado recordset
dim cn as adodb.connection ' connection
set rs = new adodb.recordset
set cn = currentproject.connection

set lv = Listview1' (name location of your listview)

rs.open "SELECT * FROM TABLE",CN,ADOPENSTATIC
' ADO RECORDSET SHOWN AS EXAMPLE TO FILL LISTVIEW

lv.listitems.clear (clear listview)

' LOOP AND FILL LISTVIEW

DO UNTIL RS. EOF
SET ITM = LV.LISTITEMS.ADD(,,RS!FIELDNAME)

' Then utilize if statement to conditionally format listview.

' Will change forecolor to red

IF RS!FIELDNAME = WHATEVER THEN
ITM.FORECOLOR = VBRED
END IF

'To change other subitems do the following

ITM.SUBITEMS(1) ' WILL BE FIRST COLUMN IN LISTVIEW

' CHANGE .SUBITEMS(1) TO .SUBITEMS(2) ETC FOR OTHER COLUMNS.

' TO CHANGE THE COLOR OF THE SUBITEMS
ITM.LISTSUBITEMS(1).FORECOLOR = VBRED '''''And so on for each column

I hope this helps let me know if you need any other help.
 
I've tried this but is doesn't seem to work. I get a compile error that says Method or data member not found.

I'm going to put my code below and mark were it's happening.

Thanks

Don

Public ColumnCount As Integer
Public itmX As ListItem
Public sValue As String
Public sFormat As String

Private Sub lvAddRowRSLocal(rs As Recordset, lv As Control, bAutoNumber As Boolean, Optional bDisplayNullAsBlank As Boolean = False)
sRoutine = "lvAddRowRSLocal"
gError.AddRoutine smodule, sRoutine
On Error GoTo Err_Routine

'*************************** ACTIVE CODE ******************************
Dim i As Integer
Dim x As Integer
Dim clmX As ColumnHeader
Dim sFieldName As String

ColumnCount = lv.ColumnHeaders.Count
sFieldName = GetParameter(LVC_FIELDNAME, lv.ColumnHeaders(1).tag)
If bAutoNumber = True Then
Set itmX = lv.ListItems.Add(, , x)
Else
If IsNull(rs(sFieldName)) Then
Set itmX = lv.ListItems.Add(, , "[Blank]")
Else
Set itmX = lv.ListItems.Add(, , CStr(rs(sFieldName)))
End If
End If

For Each clmX In lv.ColumnHeaders
If bDisplayNullAsBlank Then
sValue = "[Blank]"
Else
sValue = ""
End If
If Not clmX.Index = 1 Then
sFieldName = GetParameter(LVC_FIELDNAME, clmX.tag)
sFormat = GetParameter(LVC_FORMAT, clmX.tag)
sValue = FormatListItem(rs(sFieldName), sFormat, bDisplayNullAsBlank)
itmX.SubItems(clmX.Index - 1) = sValue
itmX.ListSubItems(1).ForeColor = vbRed
'It complains on the item above
'Doesn't seem to like the listSubItems
End If
Next clmX

'**********************************************************************

Exit_Routine:
On Error GoTo 0
gError.HandleError
Exit Sub

Err_Routine:
Select Case Err
Case 3265
sValue = "COLUMN NOT FOUND"
Resume Next
Case Else
gError.SetError Err, smodule, sRoutine
Resume Exit_Routine
End Select


End Sub
 
Try declaring itmx as :
Dim ITMX As MSComctlLib.ListItem

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top