Page 1 of 1

Coloring a line in Data Grid

Posted: Tue Apr 06, 2010 3:27 pm
by ibe
I want some of my data grid lines to act as headers that cannot be selected and are differentiated from other lines by their color. I have successfully implemented all the features I need, but if the data grid is sized so that the columns are not as wide as the data grid itself, there is a white area on the right hand side. The code I use to color the header lines is:

Code: Select all

on FillInData pData
    -- This message is sent when the Data Grid needs to populate
    -- this template with the column data. pData is the value to be displayed.
   set the text of the long id of me to pData ## temp workaround for
   SetForeGroundColor
end FillInData


setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your column template has
    -- changed. You only add script here if you want to customize the highlight.
    if pBoolean then
       set the foregroundcolor of me to empty
    end if
end dgHilite

      
private command SetForeGroundColor
   if GetDataOfIndex(the dgIndex of me, "isHeader") then
      set the opaque of me to true
      set the backgroundColor of me to 152, 206, 131
   else
      set the opaque of me to false
      set the backgroundColor of me to empty
   end if
end SetForeGroundColor
However the data grid itself knows how to draw the selection for the entire width of the grid. How could this be done through code. Image of problem can be seen here (lines 1 & 4 are headers, line 3 is the selected line:
Image

Re: Coloring a line in Data Grid

Posted: Wed Apr 07, 2010 3:53 pm
by dunbarx
Hi.

The columns in a datagrid are just fields. You could find the total width of those fields and set the width of the group.

Craig Newman

Re: Coloring a line in Data Grid

Posted: Thu Apr 08, 2010 3:00 pm
by trevordevore
Hmm, this is an interesting problem. There are no actual column controls in area where no columns are displayed (to the right of col 5 in your example). Just a graphic named dgAlternatingRows that is used to display alternating row colors.

I think your best option right now is to resize the width of column 5 so that it fills the rest of the width (set the dgColumnWidth["col 5"] of ...)

It would probably be nice if you could specify a color for a row though. The data grid would then draw the row color for you automatically.