Solved

Trouble setting the forecolor of a MSflexgrid

Posted on 2013-12-19
8
263 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now