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
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Multithreading - synchron...
by
Martin_fr
[
Today
at 01:08:18 pm]
A fairly simple sound sol...
by
VisualLab
[
Today
at 12:48:08 pm]
May be useful to somebody
by
KodeZwerg
[
Today
at 12:38:22 pm]
Can function be used for ...
by
VisualLab
[
Today
at 12:18:23 pm]
match automatic highlight...
by
Чебурашка
[
Today
at 11:35:14 am]
Tchart with dual numbers ...
by
wp
[
Today
at 10:48:18 am]
trunk compiler bug for mi...
by
Key-Real
[
Today
at 10:44:52 am]
Generics - correct syntax
by
VisualLab
[
Today
at 10:23:16 am]
Compile/Convert Delphi pr...
by
TRon
[
Today
at 09:59:52 am]
add new targets to make
by
Key-Real
[
Today
at 09:38:23 am]
Debugger crashes with App...
by
Martin_fr
[
Today
at 09:29:46 am]
Copyrights Q
by
BrassGear
[
Today
at 09:13:14 am]
[SOLVED] how to build the...
by
Key-Real
[
Today
at 09:12:33 am]
Quirky windows
by
tetrastes
[
Today
at 08:59:06 am]
How can I draw a rectangl...
by
Handoko
[
Today
at 07:30:55 am]
Draw a line in the Scroll...
by
Handoko
[
Today
at 07:27:54 am]
Offical launch of the 1 B...
by
Handoko
[
Today
at 06:05:11 am]
web development using pas...
by
Nate897
[
Today
at 02:04:05 am]
questionable function def...
by
440bx
[
Today
at 01:35:28 am]
Why isn't TTIRadioGroup's...
by
jamie
[
Today
at 12:13:45 am]
Same project and two Pcs
by
caiov1n1c1us
[
Today
at 12:04:00 am]
v3.99 code completion que...
by
440bx
[April 22, 2024, 11:08:26 pm]
[SOLVED]RichMemo StringRe...
by
KodeZwerg
[April 22, 2024, 08:44:40 pm]
[SOLVED] LAMW/Linux - Ins...
by
Alcatiz
[April 22, 2024, 08:04:06 pm]
[SOLVED] TimeStampToMSecs...
by
korba812
[April 22, 2024, 06:23:33 pm]
« previous
next »
Print
Pages: [
1
]
2
3
Author
Topic: [Solved] Colors in a DBGrid [Yes Really] (Read 18314 times)
madref
Hero Member
Posts: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
Handoko
Hero Member
Posts: 5158
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: 11923
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
Handoko
Hero Member
Posts: 5158
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
madref
Hero Member
Posts: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
Handoko
Hero Member
Posts: 5158
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
Handoko
Hero Member
Posts: 5158
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
paweld
Hero Member
Posts: 1003
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
wp
Hero Member
Posts: 11923
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: 949
..... 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.
Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey
Print
Pages: [
1
]
2
3
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[Solved] Colors in a DBGrid [Yes Really]
TinyPortal
© 2005-2018