Solved

Colors in a DBGrid control

Posted on 1998-09-05
5
212 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
[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 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

732 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