Sunday, March 11, 2012

a slight improvement to a great solution...

This is a great solution! I've modified it a bit to make it a little more
manageable though for my own use. I decided to make a version where the row
colors could be centrally managed since you have to copy the expression to
every cell in the row... and in some reports that can be a lot of cells...
this way you can define the color scheme in one place.. and you can also use
row level formatting. Here is how i did this.
Custom Code as follows:
Dim Public bgColor1 As String = "White"
Dim Public bgColor2 As String = "WhiteSmoke"
Dim Public bgColor As String = bgColor2
Public Function getBgColor(switch As Boolean) As String
If switch
If bgColor = bgColor1
bgColor = bgColor2
else
bgColor = bgColor1
end if
end if
return bgColor
End Function
Highlight the ROW and put in the following expression for BackgroundColor
property:
=Code.getBgColor(false)
Then all you have to do is go into the FIRST cell of the row and change it to:
=Code.getBgColor(true)
and walla works great (just like the original) with centralize management of
the row colors...
just a little change on a great solution...And what happens with concurrent users generating the same report?
Since bgColor is a public shared variable your code will run into problems.
Have a look at: http://odetocode.com/Articles/130.aspx
[...]
While shared methods are recommended, shared fields are definitely not. For
instance, the following code will have problems.
Public Shared Function AddToCount(ByVal Value As Integer) As String
Count = Count + value
End Function
Shared Count As Integer = 0
First, we have no control over the lifetime of the variable Count. Secondly,
if multiple users are executing the report with this code at the same time,
both reports will be changing the same Count field (that is why it is a
shared field). You don't want to debug these sorts of interactions - stick
to shared functions using only local variables (variables passed ByVal or
declared in the function body).
[...]
"thejez" <thejez@.discussions.microsoft.com> escribió en el mensaje
news:48D9ED94-AE6B-47C3-B1A9-C35DE05D4E08@.microsoft.com...
> This is a great solution! I've modified it a bit to make it a little more
> manageable though for my own use. I decided to make a version where the
> row
> colors could be centrally managed since you have to copy the expression to
> every cell in the row... and in some reports that can be a lot of cells...
> this way you can define the color scheme in one place.. and you can also
> use
> row level formatting. Here is how i did this.
> Custom Code as follows:
> Dim Public bgColor1 As String = "White"
> Dim Public bgColor2 As String = "WhiteSmoke"
> Dim Public bgColor As String = bgColor2
> Public Function getBgColor(switch As Boolean) As String
> If switch
> If bgColor = bgColor1
> bgColor = bgColor2
> else
> bgColor = bgColor1
> end if
> end if
> return bgColor
> End Function
> Highlight the ROW and put in the following expression for BackgroundColor
> property:
> =Code.getBgColor(false)
> Then all you have to do is go into the FIRST cell of the row and change it
> to:
> =Code.getBgColor(true)
> and walla works great (just like the original) with centralize management
> of
> the row colors...
> just a little change on a great solution...|||hrmmm this was supposed to be a reply to a previous post... and now i cant
even find that original post anymore (think it was posted originally on
5/27/05)...
anyway here the original post:
"G" wrote:
> Ok, I found my workaround. Someone is bound to have this issue sometime in
> the future, so I'll put the workaround here.
> I created a little routine in the custom Code area of the report that simply
> toggles and returns an integer value:
> Dim Public bgColor As Integer = 0
> Public Function alternateColor As Integer
> If bgColor = 0
> bgColor = 1
> return bgColor
> else
> bgColor = 0
> return bgColor
> end if
> End Function
> When i put my method call in the background color on the entire table ROW,
> the result was alternating COLUMN colors. This is because the method was
> called for every cell (column) in the row. In order to get alternating ROW
> color, I only called the alternateColor routine in the FIRST column in the
> table row (iif(Code.alternateColor() = 0, "white", "grey")). Each subsequent
> column in the row would simply check the "Code.bgColor" value for its
> current value, and base its color on that (iif(Code.bgColor = 0, "white",
> "grey")).
> Maybe this will come in handy for someone else someday....
> Brian
> "G" wrote in message
> news:OSJrwjtYFHA.1152@.tk2msftngp13.phx.gbl...
> > Got a dataset that is used to populate a table. Want to alternate the
> > background color on every other row in the displayed detail group. Easy
> > enough right? Here's the catch: the output is grouped at display time. A
> > query output might be:
> >
> > KEY Value1 Value2
> > A 0 1
> > A 1 0
> > B 5 0
> > C 3 0
> > C 0 7
> >
> > etc...
> >
> > The DISPLAY output is grouped on the KEY, and the two values are summed to
> > give me a display such as:
> >
> > KEY Value1 Value2
> > A 1 1
> > B 5 0
> > C 3 7
> >
> > Problem. When I use the standard "=iif(RowNumber(Nothing) MOD 2, "White",
> > "Grey")", it counts EVERY row returned from the original query, not the
> > grouped output, so I don't get a uniform white-grey-white pattern. Anyone
> > know a workaround for this?
> >
> > TIA,
> >
> > Brian
> >
>
>

No comments:

Post a Comment