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

vb6 getting cellbackcolor in msflexgrid

1,084 views
Skip to first unread message

Mojo

unread,
Oct 13, 2010, 5:41:35 PM10/13/10
to
Hi All

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

Jeff Johnson

unread,
Oct 14, 2010, 11:59:02 AM10/14/10
to
"Mojo" <ple...@dont.spam.com> wrote in message
news:YNKdnYgKkqwDuivR...@brightview.co.uk...

[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.


Chris Douce

unread,
Oct 14, 2010, 4:16:18 PM10/14/10
to
The default (standard) colors set at "design time" return 0 with the
CellBackColor property.

When you first SET the color using CellBackColor property in code, you
can read it back afterwards.

Chris

duke

unread,
Oct 15, 2010, 3:38:10 AM10/15/10
to
On Oct 13, 3:41 pm, "Mojo" <ple...@dont.spam.com> wrote:
> Hi All
>
> 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

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

Mike Williams

unread,
Oct 15, 2010, 5:48:46 AM10/15/10
to
"Mojo" <ple...@dont.spam.com> wrote in message
news:YNKdnYgKkqwDuivR...@brightview.co.uk...

> 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


Jeff Johnson

unread,
Oct 15, 2010, 9:10:15 AM10/15/10
to
"duke" <nos...@3web.net> wrote in message
news:59926d62-5d38-4cea...@i5g2000yqe.googlegroups.com...

> 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.


duke

unread,
Oct 15, 2010, 6:41:37 PM10/15/10
to
On Oct 15, 7:10 am, "Jeff Johnson" <i....@enough.spam> wrote:
> "duke" <nosp...@3web.net> wrote in message

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

Dee Earley

unread,
Oct 18, 2010, 5:54:03 AM10/18/10
to
On 14/10/2010 16:59, Jeff Johnson wrote:
> ========
> 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.
> ========

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.)

Mike Williams

unread,
Oct 18, 2010, 7:30:54 AM10/18/10
to
"Dee Earley" <dee.e...@icode.co.uk> wrote in message
news:i9h5hf$eqv$1...@speranza.aioe.org...

> On 14/10/2010 16:59, Jeff Johnson wrote:
>> ========
>> 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.
>> ========
>
> That's a bit of a hack...

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

Dee Earley

unread,
Oct 19, 2010, 4:01:15 AM10/19/10
to
On 18/10/2010 12:30, Mike Williams wrote:
> "Dee Earley" <dee.e...@icode.co.uk> wrote in message
> news:i9h5hf$eqv$1...@speranza.aioe.org...
>> On 14/10/2010 16:59, Jeff Johnson wrote:
>>> ========
>>> 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.
>>> ========
>>
>> That's a bit of a hack...
>
> 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:

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.

Mojo

unread,
Oct 19, 2010, 6:42:40 AM10/19/10
to
Hi Mike

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...

Mike Williams

unread,
Oct 19, 2010, 8:22:13 AM10/19/10
to
"Mojo" <ple...@dont.spam.com> wrote in message
news:G9mdna0wdvat6yDR...@brightview.co.uk...

> 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


Mike Williams

unread,
Oct 19, 2010, 9:01:09 AM10/19/10
to
"Dee Earley" <dee.e...@icode.co.uk> wrote in message
news:i9jjc9$6mn$1...@speranza.aioe.org...

>> "Dee Earley" <dee.e...@icode.co.uk> wrote in message>>>
>>> That's a bit of a hack...
>>
>> 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:
>
> 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.

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

Mojo

unread,
Oct 19, 2010, 9:42:04 AM10/19/10
to
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!!!

Many thanks for walking me through this.

"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message

news:i9k2hg$lkg$1...@news.eternal-september.org...

Dee Earley

unread,
Oct 19, 2010, 10:16:21 AM10/19/10
to
On 19/10/2010 14:01, Mike Williams wrote:
> "Dee Earley" <dee.e...@icode.co.uk> wrote in message
> news:i9jjc9$6mn$1...@speranza.aioe.org...
>>> "Dee Earley" <dee.e...@icode.co.uk> wrote in message>>>
>>>> That's a bit of a hack...
>>>
>>> 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:
>>
>> 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.
>
> 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,

It was targeted at Microsoft, not Jeff.
Jeff just mentioned it and gave something to reply to.

Sorry for any confusion.

Mike Williams

unread,
Oct 19, 2010, 10:21:12 AM10/19/10
to
"Mojo" <ple...@dont.spam.com> wrote in message
news:6vqdnY-796WkPSDR...@brightview.co.uk...

> 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

Jeff Johnson

unread,
Oct 19, 2010, 12:07:18 PM10/19/10
to
"Mojo" <ple...@dont.spam.com> wrote in message
news:6vqdnY-796WkPSDR...@brightview.co.uk...


> 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.


0 new messages