Solved

Trouble setting the forecolor of a MSflexgrid

Posted on 2013-12-19
8
264 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
  • 5
  • 2
8 Comments
 
LVL 46

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 46

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 46

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 46

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 46

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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