Cannot get background color of a DevExpress XtraGrid cell
I'm trying to get the background color of a DevExpress XtraGrid cell. I went through support article but it won't solve my problem (http://support.smartbear.com/viewarticle/26134/).
I'm using following code:
Sub
GetBKColor
Dim grid, view, columnId, rowIndex, column, color, attr
' Obtain the grid
' Set grid = Sys.Process("GridMainDemo").WinFormsObject("RibbonMainForm")._
' WinFormsObject("panelControl1").WinFormsObject("gcContainer")._
' WinFormsObject("FixedBands").WinFormsObject("xtraTabControl1")._
' WinFormsObject("xtraTabPage1").WinFormsObject("gridControl1")
Set
grid=
Sys.Process("iMakeHarris50056")._
WinFormsObject("MainMenu").WinFormsObject("MdiClient", "")._
WinFormsObject("frmUpdateCalendar0602")._
WinFormsObject("grpProductionCalendar").WinFormsObject("tctrlProdCalendar")._
WinFormsObject("TabPage1").WinFormsObject("SplitContainer1")._
WinFormsObject("SplitterPanel", "", 2).WinFormsObject("dgridProdCalendar")._
WinFormsObject("scOuter").WinFormsObject("SplitterPanel", "")._
WinFormsObject("scGrid").WinFormsObject("SplitterPanel", "")._
WinFormsObject("scFilter").WinFormsObject("SplitterPanel", "")
Set view = grid.WinFormsObject("iRelyDataGrid")
columnId = 5
rowIndex = 0
' Get the specified cell and obtain its backcolor
Set column = GetColumn (grid, view, columnId)
Set color = view.ViewInfo.GetGridCellInfo_2(rowIndex, column).Appearance.BackColor
' Post the results to the test log
Set attr =
Log.CreateNewAttributes
attr.BackColor = RGB(color.R, color.G, color.B)
Call
Log.Message("The backcolor of the specified cell is: " & color.Name, "", pmNormal, attr)
End
Sub
Function
GetColumn (Grid, View, ColumnId)
Dim Columns, Col, i
' Get the grid view if it is not specified
If View Is Nothing Then
Set View = Grid
End If
Set Columns = view.Columns
' Check whether the column is specified by caption or index
If
aqObject.GetVarType (ColumnId) = varOleStr Then
' Search for the column by its caption
For i = 0 To Columns.Count-1
Set Col = Columns.Item_2(i)
If Col.Caption.OleValue = ColumnId Then
Set GetColumn = Col
' The column is found
Exit Function
End If
Next
Set GetColumn = Nothing
' The column is not found
Else
' The column is specified by index
Set GetColumn = Columns.Item_2 (ColumnId)
End If
End
Function
Sub
CorrectRGBComponent(ByRef component)
component =
aqConvert.VarToInt(component)
If (component < 0) Then
component = 0
Else
If (component > 255) Then
component = 255
End If
End If
End
Sub
Function
RGB(r, g, b)
Call CorrectRGBComponent(r)
Call CorrectRGBComponent(g)
Call CorrectRGBComponent(b)
RGB = r + (g * 256) + (b * 65536)
End
Function
But after running this routine I'm getting error
Unable to find the object ViewInfo.
So I believe problematic line is:
Set color = view.ViewInfo.GetGridCellInfo_2(rowIndex, column).Appearance.BackColor
How to solve it?