Solved

Trouble setting the forecolor of a MSflexgrid

Posted on 2013-12-19
8
267 Views
Last Modified: 2013-12-19
I am trying to change this 2 column 8 row selected cells from blue to red,but it doesn't work.
Private Sub Command2_Click()
Dim Hits As Integer
Dim i As Integer
Hits = 7
On Error Resume Next 'depress error if blank cell
For i = 1 To flexStatus.Rows - 1
If flexStatus.TextMatrix(i, 0) = Hits Then
MsgBox "you won hits  " & Hits & " amount " & flexStatus.TextMatrix(i, 1)
flexStatus.Row = i
flexStatus.Col = 0
flexStatus.ForeColor = vbRed
flexStatus.Row = i
flexStatus.Col = 1
flexStatus.ForeColor = vbRed
Exit Sub
End If
Next

Open in new window

what is the problem ?
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 48

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39729987
Use CellForeColor
Dim Hits As Integer
Dim i As Integer
Hits = 7
On Error Resume Next 'depress error if blank cell
For i = 1 To flexStatus.Rows - 1
If flexStatus.TextMatrix(i, 0) = Hits Then
MsgBox "you won hits  " & Hits & " amount " & flexStatus.TextMatrix(i, 1)
flexStatus.Row = i
flexStatus.Col = 0
flexStatus.CellForeColor = vbRed
flexStatus.Row = i
flexStatus.Col = 1
flexStatus.CellForeColor = vbRed
Exit Sub
End If
Next

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39729995
Column 0 is, by default, a fixed column. You can't use ForeColor to change the colour for individual cells in fixed columns.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39730010
Column 0 is, by default, a fixed column. You can't use ForeColor to change the colour for individual cells in fixed columns.
Actually (with an MSFlexgrid at least) you can.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Martin Liss
ID: 39730026
Hold on. It was changing to red and now it isn't. Have to see what I changed.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39730095
Okay, here's a working example.
Q-28322419.zip
0
 

Author Closing Comment

by:isnoend2001
ID: 39730333
Thanks Don't about you example .zip I think it was for something else
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 39730620
Sorry about that. I now attached the correct project. If you click the command button the two sevens are highlighted. In any case you're welcome and I'm glad I was able to help.

Select the 'About Me' tab in my profile and you'll find links to some articles I've written that may interest you.

Marty - MVP 2009 to 2013
Q-28322419.zip
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39730623
Thanks Martin, I lost my way in that comment (39729995), so the posted version was very much abbreviated. Here is a much fuller explanation, even more that I originally intended.

It is still true that .ForeColor does not affect the text colour of fixed columns or rows, however that is not a full explanation.

The .ForeColor property is used to set the colour for all the non-fixed cells in the grid. By that measure it cannot affect fixed cells. There is an equivalent property of the grid - .ForeColorFixed that works all on the cells in the fixed rows and columns.

However what was really needed in this case was, as Martin showed, the .CellForeColor property which only works on the designated cell.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question