In base, is it possible to change the background color of specific records in a grid control using a macro?

I have a grid control in a subform that returns the result of a query that displays the required inventory for a build and the inventory available on hand as two columns. I would like to highlight rows or cells of the grid depending on criteria:

  • If Inventory_required > Inventory_available → Highlight Red
  • If Inventory_required = Inventory_available → Highlight Yellow
  • If Inventory_required < Inventory_available → No Highlight

I’m able to access individual rows in the macro using a while loop but I can’t seem to change the color of a specific row. Is it even possible?

I tried using both of the following lines within IF statements in order to get the color to change, but the attributes aren’t right:

oForm.getByName(“gridPartsCount”).getByName(“txtAvailableParts”).BackgroundColor = RGB(255,0,0) and
oForm.getByName(“gridPartsCount”).getByName(“txtAvailableParts”).TextColor = RGB(255,0,0)

Here is a mockup of what I would like the end result to be (highlighting was done in an image editor)

Is this possible? if so, what parameter do I need to set?

Thanks for the help!

Charles

Hello,

There is no method to set a table grid row color based upon a condition especially when applying to all the records in the control. As you found, you can set the background color but it applies to the entire grid.

@Ratslinger

Thanks for the prompt reply, I’ll try to find a different method then. Without changing the background, is there any method to format elements within a grid? Would it be possible to dynamically change a formatted field?

@thd_charles,

There is very little published on the construction of a table grid control. Accessing data is relatively simple but formatting cells or rows unknown. Modifying a column probable depending upon what is to be done. Keep in mind, the table grid is simply other controls ‘glued’ together and having data awareness with visibility of multiple records. A grid control (use in dialog - not data aware) is similar but a bit more information is available on that → UNO Grid Control

Just deleted @zerathomaz spam/comment. New spam/comment also in LO-calc: How to change border thickness in multiple worksheets.