Phew! Thought everybody had gone... what's happened to the newsgroup
world???
Just in case there are few of you left, could anybody explain to me how I
get the cellbackcolor value from an msflexgrid?
I'm using the age old method of a text box with the flexgrid to provide
editing options and this works fine, but I alternate the colour of my
msflexgrid rows and when I bring up the text box I'd just like to make its
backcolor the same as the row just to make it look a bit more professional.
Code I'm using at the mo is:
txtGridBox.Left = gridHistory.CellLeft + gridHistory.Left
txtGridBox.Top = gridHistory.CellTop + gridHistory.Top
txtGridBox.Width = gridHistory.CellWidth - 2
txtGridBox.Height = gridHistory.CellHeight
txtGridBox.BackColor = gridHistory.CellBackColor << this is the specific
one
txtGridBox.Visible = True
but I keep getting a cellbackcolor return of 0 (black) rather than the pale
blue that is there.
All of the other Cellxxxx values read fine, eg CellHeight, so how come the
colour won't come through?
Is there a way round this?
Thanks
[Please don't include "microsoft.public.vb.general" in the newsgroup list;
it doesn't exist. I don't know where people get this from.]
> Phew! Thought everybody had gone... what's happened to the newsgroup
> world???
Kids.
> txtGridBox.BackColor = gridHistory.CellBackColor << this is the specific
> one
> but I keep getting a cellbackcolor return of 0 (black) rather than the
> pale blue that is there.
Actually, according to the docs:
========
Setting either of these properties to zero causes MSHFlexGrid to paint the
cell using the standard background and foreground colors. If you want to set
either of these properties to black, set them to one instead of zero.
========
For what it's worth.
When you first SET the color using CellBackColor property in code, you
can read it back afterwards.
Chris
gridHistory.row = 1
gridHistory.col = 1
> txtGridBox.BackColor = gridHistory.CellBackColor << this is the specific
> one
> txtGridBox.Visible = True
>
> but I keep getting a cellbackcolor return of 0 (black) rather than the pale
> blue that is there.
>
> All of the other Cellxxxx values read fine, eg CellHeight, so how come the
> colour won't come through?
>
> Is there a way round this?
>
> Thanks
Try this:
txtGridBox.Left = gridHistory.CellLeft + gridHistory.Left
txtGridBox.Top = gridHistory.CellTop + gridHistory.Top
txtGridBox.Width = gridHistory.CellWidth - 2
txtGridBox.Height = gridHistory.CellHeight
gridHistory.row = 1
gridHistory.col = 1
txtGridBox.BackColor = gridHistory.CellBackColor
txtGridBox.Visible = True
Duke
> Phew! Thought everybody had gone... what's happened
> to the newsgroup world???
There are lots of people here holding the fort, and we will be here for a
very long time, despite the fact that Micro$oft have tried (and miserably
failed) to kill the newsgroups in favour of their heavily policed
advertising and propaganda forums.
> Code I'm using at the mo is [various lines snipped]:
> txtGridBox.Left = gridHistory.CellLeft + gridHistory.Left
> txtGridBox.Top = gridHistory.CellTop + gridHistory.Top
> txtGridBox.BackColor = gridHistory.CellBackColor
> txtGridBox.Visible = True
> but I keep getting a cellbackcolor return of 0 (black)
> rather than the pale blue that is there.
What "pale blue that is there"? I can't see any pale blue in your code. If
you have set one or more of the individual CellBackColor properties to pale
blue then your line . . .
txtGridBox.BackColor = gridHistory.CellBackColor
. . . would indeed correctly return the value for pale blue for that
specific cell and would assign it to the TextBox. But I cannot see any code
in your example where you are setting any of the CellBackColor properties,
either to pale blue or to anything else. I think I shall therefore assume
that you are not actually doing so, otherwise your code would work fine.
What I suspect you are actually doing is setting the BackColor property of
the entire MSFlexGrid (gridHistory.BackColor) to pale blue. This would cause
all individual cells which have their CellBackColor property set to the
default value of zero to be drawn in a pale blue background, but it would
not actually change the CellBackColor itself to pale blue (the CellBackColor
property would remain at a value of zero unless you set it otherwise).
Perhaps you would like to post more of your code, including all the relevant
parts, but in the meantime if you are doing what I think you are doing then
changing the line . . .
txtGridBox.BackColor = gridHistory.CellBackColor
. . . so that it instead reads . . .
txtGridBox.BackColor = gridHistory.BackColor
should solve your problem.
Mike
> gridHistory.row = 1
> gridHistory.col = 1
In that case he'd always get the color of row 1, and the whole point is that
his rows have ALTERNATING colors, so he wants the color of the current row.
Hi
That was my quick and simple response only to show that how the color
can be extracted.
I trust "Mojo" would realize he has to change the column / row to get
the corresponding color without my assistance.
Duke
That's a bit of a hack...
--
Dee Earley (dee.e...@icode.co.uk)
i-Catcher Development Team
iCode Systems
(Replies direct to my email address will be ignored.
Please reply to the group.)
Well you'd best get onto the people at Micro$oft who wrote the VB6 help
files then and alert them of your displeasure, because that's exactly what
they suggest you do:
CellBackColor, CellForeColor Properties
CellBackColor - Returns or sets the background colors of individual cells
or cell ranges.
CellForeColor - Returns or sets the foreground colors of individual cells
or cell ranges.
These properties are not available atdesign time.
Syntax
object.CellBackColor [=color]
object.CellForeColor [=color]
Setting either of these properties to zero paints the cell using standard
background and foreground colors.
Remarks
I don't doubt it, it's just bad design by the original author(s) of the
MSHFlexGrid control.
Using a sentinel value that is within the valid range of values makes
the whole concept moot, and then they say "to get this colour, you need
to use some other colour" to work around it.
Many thanks for coming back to me and keep up the good fight.
Apols for the confusion before I run the below code I loop through and
alternate the row colour using the following code:
' alternate row colours
If x Mod 2 = 0 Then
With gridLevels
.Row = x + 1
.Col = 1
.ColSel = 13
.FillStyle = flexFillRepeat
.CellBackColor = 16115420 ' pale blue
.ColSel = 0
End With
End If
When the textbox is positioned over the appropriate cell I just wanted to
make the textbox the same as the background cell so I thought it would be as
simple as I've put down.
I'm stumped!?!?!
"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:i9981n$n7o$1...@news.eternal-september.org...
> Apols for the confusion before I run the below code I loop
> through and alternate the row colour using the following code:
> ' alternate row colours
> If x Mod 2 = 0 Then
> With gridLevels
> .Row = x + 1
> .Col = 1
> .ColSel = 13
> .FillStyle = flexFillRepeat
> .CellBackColor = 16115420 ' pale blue
You haven't shown your loop counters so I don't know if the line "Row = x +
1" is doing exactly what you want it to (or if there is perhaps an
equivalent and possibly unnecessary line in whatever Grid Click event code
you are using) but If you are setting the CellBackColour of the cells in
each alternative row to light blue and if you are leaving the CellBackColor
of the other rows alone (at their default setting of zero), as you appear to
be doing, then you should pick up the pale blue for the textBox BackColor
okay in your Click event code when the click is on a pale blue cell but you
will pick up zero (the equivalent of black) when it is NOT on a pale blue
cell. Otherwise (if for example your are inadvertently also using ".Row = x
+ 1" in your Click event code) then you will get the opposite of black when
the click is on a pale blue cell and pale blue when it is not. Neither of
those outcomes agrees with your description of your problem, where you
appear to be saying that you are not getting pale blue whichever cell you
click on.
There are all sorts of different ways of doing what you appear to be doing,
but it it would be interesting to find out why the method you are currently
using is not working as you appear to expect it to work, and the best way to
solve that problem is for you to post your /entire/ code that deals with
this specific FlexGrid Control so that we can see exactly what you are doing
with it in all the routines that appy to it.
Mike
Yes, it is bad design by the original author(s) of the MSHFlexGrid control,
but it /is/ what they designed and, hack or not, the suggestion of using a
value of 1 when you really wanted black /is/ what Micro$oft have advised
people to do, and Jeff Johnson was merely reiterating Micro$oft's advice in
that respect when he mentioned it to the OP. I therefore decided to point
out that your own "that's a hack" response to Jeff Johnson was not actually
necessary, since it was not Jeff's hack, and especially since your response
added nothing useful to the conversation and was no help whatsoever as far
as the OP was concerned. I therefore thought it might be useful to tell you
about it being a "Micro$oft official hack", since you had at that point
given no indication that such informastion was already in your possession,
in order that you could address your obvious concerns about it to the people
at Micro$oft who produced it and who have advised people to use it.
Mike
Many thanks once again.
As you probably thought, I was one row out so I was getting nothing rather
than the blue. Soon as I corrected my index issue, blue bg it is!!!
Many thanks for walking me through this.
"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:i9k2hg$lkg$1...@news.eternal-september.org...
It was targeted at Microsoft, not Jeff.
Jeff just mentioned it and gave something to reply to.
Sorry for any confusion.
> Hi Mike
> Many thanks once again.
> As you probably thought, I was one row out so I was
> getting nothing rather than the blue. Soon as I corrected
> my index issue, blue bg it is!!!
Good. I thought something like that might be the case, which is why I made
specific mention in a number of places in my response regarding your
incrementing of the .Row property.
> Many thanks for walking me through this.
You're very welcome. By the way, just for future reference, it isn't always
easy in cases like this to see what is going on when we have only a couple
of snippets of code to go on, and so it is usually best if you post as much
of the relevant code as you can. Anyway, glad you've got it all working now.
Mike
> As you probably thought, I was one row out so I was getting nothing rather
> than the blue. Soon as I corrected my index issue, blue bg it is!!!
...? So does this mean you NEVER tried it on a "regular" row? Because if you
had you should have noticed that the text box was the color of the opposite
row.