Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to paint the dbgrid rows by different colors depending conditional values. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Sep-05
Category
Database-VCL
Language
CBuilder 6.x
Views
251
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Zvonicek, Pavel
Reference URL:
			1   
2   /*
3   this code shows how to paint the dbgrid rows by different 
4   colors depending conditional values (on content of data fields)
5   
6   */
7   void __fastcall TCLVPOdvadeni::DBGrid1DrawColumnCell(TObject *Sender,
8         const TRect &Rect, int DataCol, TColumn *Column,
9         TGridDrawState State)
10  {
11      char f_name [25] = {0};
12      strcpy (f_name, Column->FieldName.c_str());
13  
14      if (strcmp(f_name, "POCET_KUSU") && strcmp(f_name, "ODVEDENO") && 
15  strcmp(f_name, "NAHRADA")
16          && strcmp(f_name, "ZMETKY") && strcmp(f_name, "ZBYVA"))
17      {
18          AnsiString ret = Column->Field->Text;
19  
20          // Stornovane VP
21          if 
22  (ClientDataModule->VyrobniPrikaz_IBCDS->FieldByName("AKTIVITA")->AsString == "S")
23          {
24              DBGrid1->Canvas->Brush->Color = clAqua;
25              DBGrid1->Canvas->Brush->Style = bsSolid;
26              DBGrid1->Canvas->Pen->Width = 2;
27              DBGrid1->Canvas->Pen->Color = clAqua;
28              DBGrid1->Canvas->TextRect(Rect,Rect.Left+2,Rect.Top+2,ret);
29              return;
30          }
31  
32          // Oznaceni zpracovanych - pokrytych VP
33          if (ClientDataModule->VyrobniPrikaz_IBCDS->FieldByName("ZBYVA")->AsInteger 
34  == 0)
35          {
36              if 
37  (ClientDataModule->VyrobniPrikaz_IBCDS->FieldByName("CISLO_RS")->AsString.IsEmpty())
38              {
39                  DBGrid1->Canvas->Brush->Color = (TColor)0x0000BBFF;
40                  DBGrid1->Canvas->Brush->Style = bsSolid;
41                  DBGrid1->Canvas->Pen->Width = 2;
42                  DBGrid1->Canvas->Pen->Color = (TColor)0x0000BBFF;
43                  DBGrid1->Canvas->TextRect(Rect,Rect.Left+2,Rect.Top+2,ret);
44              }
45              else {  // Odvedene z RS
46                  DBGrid1->Canvas->Brush->Color = clNavy;
47                  DBGrid1->Canvas->Brush->Style = bsSolid;
48                  DBGrid1->Canvas->Pen->Width = 2;
49                  DBGrid1->Canvas->Pen->Color = clNavy;
50                  DBGrid1->Canvas->FillRect(Rect);
51  
52                  DBGrid1->Canvas->Brush->Color = (TColor)0x0000BBFF;
53                  DBGrid1->Canvas->Brush->Style = bsSolid;
54                  DBGrid1->Canvas->Pen->Width = 2;
55                  DBGrid1->Canvas->Pen->Color = (TColor)0x0000BBFF;
56                  TRect R = Rect;
57                  R.Left+=2;
58                  R.Top+=2;
59                  R.Right-=2;
60                  R.Bottom-=2;
61                  DBGrid1->Canvas->TextRect(R,Rect.Left+3,Rect.Top+2,ret);
62              }
63              return;
64          }
65  
66          // Reklamace
67          if 
68  (!ClientDataModule->VyrobniPrikaz_IBCDS->FieldByName("CISLO_RS")->AsString.IsEmpty()
69  )
70          {
71              DBGrid1->Canvas->Brush->Color = clNavy;
72              DBGrid1->Canvas->Brush->Style = bsSolid;
73              DBGrid1->Canvas->Pen->Width = 2;
74              DBGrid1->Canvas->Pen->Color = clNavy;
75              DBGrid1->Canvas->Font->Color = clWhite;
76              DBGrid1->Canvas->Font->Style = TFontStyles () << fsBold;
77              DBGrid1->Canvas->FillRect(Rect);
78  
79              DBGrid1->Canvas->Brush->Color = (TColor) 0x000000DD;
80              TRect R = Rect;
81              R.Left+=2;
82              R.Top+=2;
83              R.Right-=2;
84              R.Bottom-=2;
85              DBGrid1->Canvas->TextRect(R,Rect.Left+3,Rect.Top+2,ret);
86              return;
87          }
88  
89          // Skluzove VP
90          if 
91  (ClientDataModule->VyrobniPrikaz_IBCDS->FieldByName("TERMIN_ODVEDENI")->AsDateTime <
92                  datum_dnes)
93          {
94              DBGrid1->Canvas->Brush->Color = (TColor)0x000055FF;
95              DBGrid1->Canvas->Brush->Style = bsSolid;
96              DBGrid1->Canvas->Pen->Width = 2;
97              DBGrid1->Canvas->Pen->Color = (TColor)0x000055FF;
98              DBGrid1->Canvas->TextRect(Rect,Rect.Left+2,Rect.Top+2,ret);
99          }
100         // V souladu s terminem dokonceni
101         else
102         {
103             DBGrid1->Canvas->Brush->Color = clLime;
104             DBGrid1->Canvas->Brush->Style = bsSolid;
105             DBGrid1->Canvas->Pen->Width = 2;
106             DBGrid1->Canvas->Pen->Color = clLime;
107             DBGrid1->Canvas->TextRect(Rect,Rect.Left+2,Rect.Top+2,ret);
108         }
109     }
110 
111 }
112 //---------------------------------------------------------------------------


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC