2
votes

this is my scenario. I have a customized pane in syspro that is a listview that displays data fetched by a sql query. Now what I want to achieve is to highlight the rows that applies to certain criteria. How do I that using VBScript? I found the following code but have not get it to work? Is there something wrong with this code:

  Public Sub Color_Row(intLineCount As Long, RowColor As OLE_COLOR)
  Dim itmIdx As ListItem
  Dim lstSI As ListSubItem
  Dim intIdx As Integer

  On Error GoTo ErrorRoutine 

  Set itmIdx = CustomizedPane.CodeObject.ListItems(intLineCount)
  itmIdx.ForeColor = RowColor
  For intIdx = 1 To CustomizedPane.CodeObject.ColumnHeaders.Count - 1
  Set lstSI.ForeColor = itmIdx.ListSubItems(intIdx)
  lstSI.ForeColor = RowColor
  Next
  Set itmIdx = Nothing
  Set lstSI = Nothing
  Exit Sub

  ErrorRoutine :
  MsgBox Err.Description
  End Sub

I found that code at http://www.vbforums.com/showthread.php?231157-VB-Color-a-row-in-a-ListView.

How can I color a specific row in the listview?

1
Look at using ItemDataBound event. This is fired as each item is bound in a list view. You can then compare the item an if it matches your criteria you can colour the item... make it bold or any other style change. - Mych
Yes, the way I have read the data is by using an already previous written script that automatically loads the data queried by the SQL string and stores it in a rs variable.Then it loops through every record in rs until it reaches EOF - Ruaan Volschenk
Ok you are not binding the data but adding an item to the list in a loop. So as you loop do a comparison. If match apply style changes to that item then move to next in loop - Mych

1 Answers

1
votes

You were activating your listsubitem as a forecolor object.

From this:

  Set lstSI.ForeColor = itmIdx.ListSubItems(intIdx)

To This:

  Set lstSI = itmIdx.ListSubItems(intIdx)

Completed Code:

Public Sub Color_Row(intLineCount As Long, RowColor As OLE_COLOR)
    Dim itmIdx As ListItem
    Dim lstSI As ListSubItem
    Dim intIdx As Integer

    On Error Goto ErrorRoutine 

    Set itmIdx = CustomizedPane.CodeObject.ListItems(intLineCount)
    itmIdx.ForeColor = RowColor
    For intIdx = 1 To CustomizedPane.CodeObject.ColumnHeaders.Count - 1
        Set lstSI = itmIdx.ListSubItems(intIdx)
        lstSI.ForeColor = RowColor
    Next
    Set itmIdx = Nothing
    Set lstSI = Nothing
    Exit Sub

    ErrorRoutine :
    MsgBox Err.Description
End Sub