Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CustomPaintSite

0 views
Skip to first unread message

Martin Frey

unread,
Jun 4, 2004, 7:08:09 AM6/4/04
to
I have a jdbTable in which i want to paint a row (Background) depending on a
value of a column in the prior row.
To specify this a little, i have a Column which holds a Date and i sort the
table according to these dates. now i want to paint all rows with the same
date value with the same background.

now say the table will look like this:

DATE , Some Text
01.01.2004 , text 1 -> white
01.01.2004 , text 2 -> white
02.01.2004 , text 3 -> gray
02.01.2004 , text 4 -> gray
03.01.2004 , text 5 -> white
04.01.2004 , text 6 -> gray
and so on.

I found out that i can easily get the value of a column of the prior row but
not a background color. i think this is because i can't get a component from
a prior row, but im not sure.

can someone help me with this?

thank you
martin


Martin Frey

unread,
Jun 4, 2004, 9:08:33 AM6/4/04
to
Ok i solved the problem without getting a background from a prior cell.
here's the code:

private Color currentColor = Color.white;
private row currentRow = 0;

public void column_painting(DataSet dataSet, Column column, int row, Variant
value, CustomPaintSite paintSite) {
if (row == 0) {
priorColor = Color.white;
priorRow = 0;
}
else {
DataRow dr = new DataRow(dataSet);
dataSet.getDataRow(row, dr);
Date date = dr.getDate("DATE");

DataRow priorDR = new DataRow(dataSet);
dataSet.getDataRow(row-1, priorDR);
Date priorDate = priorDR.getDate("DATE");
if (date != null && priorDate != null && !date.equals(priorDate) &&
row != priorRow) {
if (priorColor.equals(Color.white)) {
priorColor = new Color(220, 220, 220);
}
else {
priorColor = Color.white;
}
priorRow = row;
}
}
paintSite.setBackground(priorColor);
}


Paul Furbacher [TeamB]

unread,
Jun 4, 2004, 9:12:43 AM6/4/04
to
Martin Frey wrote:

Here are some ideas, none of which have been tested:

1. Add a private static variable to the custom paint site class.
Update it every time the relevant method of the site object
gets called. Since you are essentially toggling between
two colors, use a boolean.

The update will set the current color based on the value
of the static variable and whether the date has changed.

This may not work if painting is not done by iterating rows
from row 0.


2. An alternative might be to use a hidden calculated column,
the values of which are 0/1 or true/false, and are calculated
once, upon loading. The value is toggled based on the same
criterion you stated above. Get the value of that column
for the current row and use that to determine the color.


--


Paul Furbacher (TeamB)

Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.

0 new messages