Solved

Colors in a DBGrid control

Posted on 1998-09-05
5
206 Views
Last Modified: 2010-04-30
Hi,

I need to set a color to a diferents rows, any idea how can I do that. I'll really apreciate your help.
0
Comment
Question by:tulio
5 Comments
 

Expert Comment

by:protogeek
ID: 1433224
Assuming you want to set every other row to be a different color,
how about iterating through the recordset, and determining if it's an even or odd row. Then you can set the background color just for that row.   e.g.

   Dim rst as Recordset
   Dim i as Integer
   For i = 1 To rst.RecordCount
        If (i Mod 2 = 0) Then
           'set the background color
           'I don't have VB on my home system so I don't know
           'the syntax offhand for changing the background prop.
           'of the row
        next i
    End if

0
 

Expert Comment

by:protogeek
ID: 1433225
oops. obviously I switched the End If and next i statements.
0
 

Author Comment

by:tulio
ID: 1433226
I tried to use this code and it change the entire color of the DBGrid background. I need to have diferents row colors depends on a criteria, for instance: All the rows whose CountryCode is "USA" in red and the rest in blue. If you have another solution please let me know ASAP. Thanks one more time for your cooperation.


0
 
LVL 2

Expert Comment

by:shchuka
ID: 1433227
If you are using the DBGrid that came with VB, you can't really do it - all the rows will be the same color.

If you need different rows in different colors, then you need the DBGrid Pro from Apex Software (www.apexsc.com), which allows you that and much, much more...
0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1433228
You can't change the grid of individual rows. You have to use the MSFlexgrid for that purpose.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now