Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trouble setting the forecolor of a MSflexgrid

Posted on 2013-12-19
8
Medium Priority
?
269 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 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 49

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 49

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 49

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

Independent Software Vendors: 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!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

650 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