这是我的情景。我在syspro中有一个自定义窗格,它是一个列表视图,显示由sql查询提取的数据。现在我想要实现的是突出显示适用于某些条件的行。我如何使用VBScript?我发现以下代码,但没有让它工作?这段代码有什么问题:
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
我在http://www.vbforums.com/showthread.php?231157-VB-Color-a-row-in-a-ListView找到了代码。
如何为列表视图中的特定行着色?
答案 0 :(得分:1)
您将listubitem激活为forecolor对象。
由此:
Set lstSI.ForeColor = itmIdx.ListSubItems(intIdx)
To This:
Set lstSI = itmIdx.ListSubItems(intIdx)
完成代码:
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