Solved

Colors in a DBGrid control

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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