Solved

Trouble setting the forecolor of a MSflexgrid

Posted on 2013-12-19
8
262 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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
Hold on. It was changing to red and now it isn't. Have to see what I changed.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

Expert Comment

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

Author Closing Comment

by:isnoend2001
Comment Utility
Thanks Don't about you example .zip I think it was for something else
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

743 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

8 Experts available now in Live!

Get 1:1 Help Now