Setting background colour for a row in a grid

Hi all.

I’m using a grid to display mechanical testing requirements and test results. I would like to be able to set the background colour of individual rows … when not the active row … depending on the row state. For example, a shade of red for FAILED tests, and possibly green for OK results.

I’ve been having a look at available grid row settings using intellisense, but haven’t spotted anything obvious relating to colour control. Can anyone offer advice? I use the following code … provided through an earlier forum post … to set focus to the cell where data entry is required.

row = DirectCast(grid.GridControl.DataGridObj.GetContainerFromIndex(1), Xceed.Wpf.DataGrid.DataRow)|
row.Cells(1).Focus()

Can row background colour be specified using this approach … or is there a more obvious method :slight_smile:
Any advice will be appreciated.

Regards,
Greg Shearer

Any advice on this would still be appreciated. I know this must be possible, but I have had no luck at all provided from Google or Intellisense within Factory Studio.

Regards,
Greg Shearer

I’ve stumbled on a basic method through the documentation covering dynamic cell colours in reports :slight_smile: Now I just need to adapt it to my specific requirements.

As hoped … it wasn’t hard … just not immediately obvious …

index = grid.GridControl.DataGridObj.SelectedIndex + 1
row = DirectCast(grid.GridControl.DataGridObj.GetContainerFromIndex(index), Xceed.Wpf.DataGrid.DataRow)
row.Cells(1).Focus()
row.Background = Brushes.Blue

Turns out that this method works … but doesn’t suit my application. The application will generally have a set of ‘shown’ rows which is greater than the number or rows visible within the grid.

I need to be able to set the colour of the row even if it is off the bottom of the visible grid, but this method appears to blow up if the index used is outside the visible range.

I’m after a simple method to specify the background colour for any grid ‘shown’ row, and also to return it to the original colour if/when the condition is reversed.

How hard can it be :slight_smile:
Any advice will be really appreciated!

Regards,
Greg Shearer

I am making some progress … but it is slow.

Can anyone tell me how to determine the default row background colours for the alternating grid rows.
I can do this … rather unreliably … by saving the background colours of the top two grid rows on a nominal first pass of the grid.

I think all my problems may be solved if I can simply obtain these colours from a system function.

I want to be able to set the data grid default row background colours like this …

image

but there don’t appear to be properties available within the TDataGridWindow class …