Okay I have read the documents and I even copied the code from the example and I still am getting an out of bounds error.
// Original code I came up with... throws out of bounds exception...
'If ( column = 1 ) Then // Quantity Value...
'If ( Me.CellTextAt( row, column ).ToInt64 <= 0 ) Then
'g.DrawingColor = Color.RGB( 255, 69, 0 ) // Orange Red...
'Else
'g.DrawingColor = Color.RGB( 0, 153, 51 ) // North Texs Green...
'End If
'End If
// Error appears first line of code it's an out of bounds acceptation...
If Me.CellTagAt( row, column ) = "0" Then
g.DrawingColor = Color.Red'RGB(255, 0, 0)
g.FillRectangle(0, 0, g.Width, g.Height)
Else
g.DrawingColor = Color.Green'RGB(255, 0, 0)
g.FillRectangle(0, 0, g.Width, g.Height)
End If
In your screenshot row=10. If there are fewer than 11 rows in the list then trying to access the 11th row’s cell tags will raise an OutOfBoundsException.
Try adding a check that compares the row to the LastAddedRowIndex property, and only access the cell tags of rows that have actually been added:
If row <= Me.LastAddedRowIndex Then
If Me.CellTagAt( row, column ) = "0" Then
if row <= me.lastrowindex then
If Me.CellTagAt( row, column ) = "0" Then
g.DrawingColor = Color.Red'RGB(255, 0, 0)
g.FillRectangle(0, 0, g.Width, g.Height)
Else
g.DrawingColor = Color.Green'RGB(255, 0, 0)
g.FillRectangle(0, 0, g.Width, g.Height)
End If
end if
Jeff and Andrew, thanks that worked. But it paints the entire column. I’m looking to just paint a cell that meets the criteria. Is this possible? Column 1 cells where the inventory value is located.
PaintCellBackground is raised for every cell in view. If you only want to paint a certain cell you need to check that before getting down to the sample Jeff posted.
Something like this:
// No OOBE, thanks
if row > me.LastRowIndex then return false
// Only painting in column 1, the inventory value
if column <> 1 then return false
// wut is this data type clobbering?
// we sure it's not supposed to be an integer or boolean?
if me.CellTagAt(row, column) = "0" then
g.DrawingColor = Color.Red
else
g.DrawingColor = Color.Green
end
// Got our color, we're in the right column, paint the color
g.FillRectangle(0, 0, g.Width, g.Height)
Thanks Tim, I’ll give this a try and see what happens! Perfect! Thanks again! I am curious though in the two preceding If statements they are to return false, where is that return going and how does it work?
It says ‘I didnt do any painting, so I’m letting the normal stuff happen’
Return true means ‘I did all that was needed, please dont draw on top of my stuff’