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
Solved

Colors in a DBGrid control

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 59
How to hault or freeze parent form when a 2d form is open in vb6 3 40
How to read File Date Created using VB6 8 52
pop out of webbrowser1 control vba6 5 25
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

828 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