Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
[Solved] Colors in a DBGrid [Yes Really]
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Cannot get FTP to work
by
garymq
[
Today
at 02:54:07 am]
Infernal error when decom...
by
Fibonacci
[
Today
at 12:56:28 am]
Linking a PortAudio stati...
by
Fred vS
[May 18, 2026, 10:53:41 pm]
Feature suggestion - repe...
by
ASerge
[May 18, 2026, 09:15:26 pm]
Anubis activated
by
440bx
[May 18, 2026, 09:14:22 pm]
When will lazarus actuall...
by
Curt Carpenter
[May 18, 2026, 08:59:21 pm]
wildcard utilities list
by
mas steindorff
[May 18, 2026, 08:35:41 pm]
StringGrid: which is "cur...
by
Bart
[May 18, 2026, 08:18:51 pm]
LazNodeEditor (visual nod...
by
fcu
[May 18, 2026, 07:16:40 pm]
TShellTreeView TopItem
by
Paolo
[May 18, 2026, 06:53:15 pm]
duplicate an Object at ru...
by
Thaddy
[May 18, 2026, 03:57:51 pm]
How to wait until a WebDA...
by
Hartmut
[May 18, 2026, 03:47:14 pm]
Can /my/ AI help me with ...
by
microxa
[May 18, 2026, 01:16:57 pm]
Nothing but chaotic attem...
by
mdalacu
[May 18, 2026, 12:45:46 pm]
Flamerobin error-message
by
Zvoni
[May 18, 2026, 09:11:06 am]
search via TSQLQuery
by
Zvoni
[May 18, 2026, 08:55:43 am]
Can I enter MySQL prompt ...
by
Zvoni
[May 18, 2026, 08:50:42 am]
TLazSerial : serial port ...
by
mas steindorff
[May 17, 2026, 10:50:34 pm]
PopupMenu on dock menu
by
systemgvp
[May 17, 2026, 08:32:50 pm]
[SOLVED] Dark Theme
by
Hansvb
[May 17, 2026, 07:29:22 pm]
Bug with constref?
by
LemonParty
[May 17, 2026, 07:15:45 pm]
FPC Unleashed (inline var...
by
Okoba
[May 17, 2026, 03:49:31 pm]
is this code correct?
by
Thaddy
[May 17, 2026, 03:23:29 pm]
Anubis's website security...
by
ALLIGATOR
[May 17, 2026, 02:45:52 pm]
Pure Pascal LZ4, LZ5 and ...
by
LemonParty
[May 17, 2026, 01:38:07 pm]
« previous
next »
Print
Pages: [
1
]
2
3
Author
Topic: [Solved] Colors in a DBGrid [Yes Really] (Read 22029 times)
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
[Solved] Colors in a DBGrid [Yes Really]
«
on:
December 14, 2017, 12:31:56 pm »
Is it possible to have color columns in a DBGrid?
In my example where the 'X' is?
«
Last Edit: December 23, 2017, 12:40:19 am by madref
»
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Handoko
Hero Member
Posts: 5538
My goal: build my own game engine using Lazarus
Re: Colors in a DBGrid
«
Reply #1 on:
December 14, 2017, 01:03:27 pm »
I haven't tried but I think it is possible. Because TDBGrid has
OnPrepareCanvas
event, which can be used to change its color when painting.
See my example on TStringGrid here, maybe you can adapt it to TDBGrid:
http://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361
Logged
wp
Hero Member
Posts: 13515
Re: Colors in a DBGrid
«
Reply #2 on:
December 14, 2017, 04:14:35 pm »
Quote from: madref on December 14, 2017, 12:31:56 pm
Is it possible to have color columns in a DBGrid?
In my example where the 'X' is?
I don't understand: You want to colorize individual
columns
, but the 'X's are in individual
cells
.
For the entire columns you can adjust the Color property of each TColumn. For the individual cells you should follow Handoko's post and use the OnPrepareCanvas event in which you can specify any Canvas properties dependant on data values.
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #3 on:
December 19, 2017, 12:33:55 pm »
When i try to use this
Code: Pascal
[Select]
[+]
[-]
procedure
TForm_Wedstrijden_Overzicht
.
DBGrid_WedstrijdenPrepareCanvas
(
sender
:
TObject
;
DataCol
:
Integer
;
Column
:
TColumn
;
AState
:
TGridDrawState
)
;
begin
end
;
I get an internal error 200611031
What is that???
[Found out why !!!]
i was doing this in another unit and it's completely 100% Delphi but not Lazarus.
Code: Pascal
[Select]
[+]
[-]
function
SingleQuotedStr
(
St
:
String
)
:
String
;
begin
SingleQuotedStr
:
=
Chr
(
39
)
+
St
+
Chr
(
39
)
;
end
;
// SingleQuotedStr
and it should be:
Code: Pascal
[Select]
[+]
[-]
function
SingleQuotedStr
(
St
:
String
)
:
String
;
begin
Result
:
=
Chr
(
39
)
+
St
+
Chr
(
39
)
;
end
;
// SingleQuotedStr
«
Last Edit: December 25, 2017, 11:47:44 am by madref
»
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Handoko
Hero Member
Posts: 5538
My goal: build my own game engine using Lazarus
Re: Colors in a DBGrid
«
Reply #4 on:
December 19, 2017, 01:10:53 pm »
Can you provide the whole compilable code for us to test? If you're not willing to publicize the project, you can write a sample project that show the error.
I put this code below on my test project, I didn't get the problem like yours:
Code: Pascal
[Select]
[+]
[-]
procedure
TfrmProduk
.
DBGrid1PrepareCanvas
(
sender
:
TObject
;
DataCol
:
Integer
;
Column
:
TColumn
;
AState
:
TGridDrawState
)
;
begin
//
end
;
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #5 on:
December 19, 2017, 02:40:15 pm »
Hmmm..... this is really strange.
I have made a skeleton version of my database so i could put it up here so that you all can try and solve my problem.
But while doing so i found the solution myself with the following code:
Code: Pascal
[Select]
[+]
[-]
procedure
TForm_Wedstrijden_Overzicht
.
DBGrid_WedstrijdenPrepareCanvas
(
sender
:
TObject
;
DataCol
:
Integer
;
Column
:
TColumn
;
AState
:
TGridDrawState
)
;
begin
// Highlight selected column's header with green
if
(
DataCol
=
12
)
then
if
Column
.
Field
.
AsString
=
'x'
then
(
sender as TDBGrid
)
.
Canvas
.
Brush
.
Color
:
=
clGreen
;
end
;
Now i am putting it in my original database and now i get this stupid error.
And the error doesn't point to my unit/form that i am using but to a helping unit
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #6 on:
December 19, 2017, 02:43:47 pm »
Even stanger....
I deleted my Lib-directory, recompiled everything and now its working
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Handoko
Hero Member
Posts: 5538
My goal: build my own game engine using Lazarus
Re: [Solved] Colors in a DBGrid
«
Reply #7 on:
December 19, 2017, 02:56:37 pm »
Glad to hear your issue has been solved.
Me too ever had problems that the code didn't work as it should be, simply deleting the lib folder and recompiling solved it.
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #8 on:
December 20, 2017, 09:30:49 am »
I have put this back to [Unsolved] because i want to know if it is also possible to give colors to individual ROWS in a DBGrid?
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Handoko
Hero Member
Posts: 5538
My goal: build my own game engine using Lazarus
Re: Colors in a DBGrid
«
Reply #9 on:
December 20, 2017, 09:37:25 am »
I haven't tested it on TDBGrid, but int TStringGrid it is possible:
Code: Pascal
[Select]
[+]
[-]
procedure
TMainForm
.
StringGrid1PrepareCanvas
(
sender
:
TObject
;
aCol
,
aRow
:
Integer
;
aState
:
TGridDrawState
)
;
begin
if
not
(
Sender
=
StringGrid1
)
then
Exit
;
if
(
aRow
=
2
)
then
StringGrid1
.
Canvas
.
Brush
.
Color
:
=
clYellow
;
end
;
«
Last Edit: December 20, 2017, 09:39:52 am by Handoko
»
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #10 on:
December 20, 2017, 10:03:22 am »
Yes but DBGrid has no
aRow
.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm_Wedstrijden_Overzicht
.
DBGrid_WedstrijdenPrepareCanvas
(
sender
:
TObject
;
DataCol
:
Integer
;
Column
:
TColumn
;
AState
:
TGridDrawState
)
;
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
paweld
Hero Member
Posts: 1617
Re: Colors in a DBGrid
«
Reply #11 on:
December 20, 2017, 10:56:08 am »
Code: Pascal
[Select]
[+]
[-]
procedure
TForm_Wedstrijden_Overzicht
.
DBGrid_WedstrijdenPrepareCanvas
(
sender
:
TObject
;
DataCol
:
Integer
;
Column
:
TColumn
;
AState
:
TGridDrawState
)
;
begin
//For every third row
if
(
Sender as TDBGrid
)
.
Datasource
.
Dataset
.
RecNo
mod
3
=
0
then
(
Sender as TDBGrid
)
.
Canvas
.
Brush
.
Color
:
=
clYellow
;
//When 'x' value in 5 data field
if
(
Sender as TDBGrid
)
.
Datasource
.
Dataset
.
Fields
[
5
]
.
AsString
=
'x'
then
begin
(
Sender as TDBGrid
)
.
Canvas
.
Font
.
Style
:
=
[
fsBold
]
;
(
Sender as TDBGrid
)
.
Canvas
.
Brush
.
Color
:
=
clGreen
;
end
;
end
;
Logged
Best regards / Pozdrawiam
paweld
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #12 on:
December 20, 2017, 12:51:39 pm »
But what if i want to have 3 rows of white and then 3 rows of yellow and then 3 rows of white, etc, etc?
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
wp
Hero Member
Posts: 13515
Re: Colors in a DBGrid
«
Reply #13 on:
December 20, 2017, 12:55:25 pm »
Hey come on. Use your brain! Look at paweld's solution. Suppose you have a series of number 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... Which math operation is needed to group these numbers by 3?
Logged
madref
Hero Member
Posts: 1116
..... A day not Laughed is a day wasted !!
Re: Colors in a DBGrid
«
Reply #14 on:
December 20, 2017, 01:12:31 pm »
Yes but my brains are not working properly to get a solution
My brains knows the solution but i can't program it
it something like this
if mod 3 = 0 then change colour overtime
«
Last Edit: December 20, 2017, 01:14:46 pm by madref
»
Logged
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.
Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa
Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)
Print
Pages: [
1
]
2
3
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[Solved] Colors in a DBGrid [Yes Really]
TinyPortal
© 2005-2018