2

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?

3
  • 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. Commented Mar 19, 2014 at 9:50
  • 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 Commented Mar 19, 2014 at 10:01
  • 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 Commented Mar 19, 2014 at 12:24

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.