Checkbox in NextDBGrid
#1
Posted 11 February 2007 - 07:48 PM
i will show a checkbox in the NextDBGrid but it dont work,
i have a Data Field with boolean,
in ColumnCreate i put this:
if Field.FieldName = 'Fertig' then ColumnClass := TNxDBCheckBoxColumn;
but the field in the grid is empty and show nothing.
Many thanks
#2
Posted 12 February 2007 - 08:26 AM
You will need to set ValueChecked and ValueUnchecked properties in TNxDBCheckBoxColumn.
If this is boolean field, you may set if to:
ValueChecked: true
ValueUnchecked: false
Also you may try with capitalizing first letter (True, False)
You may have any kind of Field for checkbox column, all you have to know is that:
if Field.AsString = ValueChecked ----> checkbox will be shown and checked.
if Field.AsString = ValueUnchecked ----> checkbox will be shown but unchecked.
otherwise cell will be empty.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#3
Posted 13 February 2007 - 10:30 AM
I have try this:
var ColumnClass: TNxDBColumnClass; var AddColumn: Boolean);
begin
if Field.FieldName = 'Fertig' then ColumnClass := TNxDBCheckBoxColumn;
end;
procedure TForm1.NextDBGrid1ColumnAdded(Sender: TObject;
Column: TNxDBCustomColumn);
begin
if Column is TNxDBCheckBoxColumn then
begin
with Column as TNxDBCheckBoxColumn do
begin
Width:=30;
ValueChecked:='True';
ValueUnchecked:='False';
end;
end;
end;
But this dont work, there are no checkbox in the Grid.
I have try it again with ValueChecked:='true' but thats the same.
In the database the value is 'True'
regards
#4
Posted 13 February 2007 - 10:37 PM
Very strange. Try to change line:
into
to read values from field.
Then you may set ValueChecked and ValueUnchecked again.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#5
Posted 14 February 2007 - 11:54 AM
thank you for this tipp, i dont now why but the Values are 'Wahr' and 'Falsch'. (in the Preview there was 'true' and 'false')
I change it in ValueChecked and now it works fine.
#6
Posted 15 February 2007 - 04:46 AM
Probably localization settings have change it.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#7
Posted 15 February 2007 - 12:09 PM
b:=True;
{ first example }
//BoolToStr(b) = '-1' (* true *)
//BoolToStr(NOT b) = '0' (* false *)
{ second example }
SetLength(TrueBoolStrs,1);
SetLength(FalseBoolStrs,1);
TrueBoolStrs[0]:='YES';
FalseBoolStrs[0]:='NO';
ShowMessage(BoolToStr(True, True));
//this will result in 'YES'
ShowMessage(BoolToStr(False, True));
//this will result in 'NO'
Basically TrueBoolStrs and FalseBoolStrs can be filled with lots of strings representing true and false.
Furthermore You might also have a look at the counterparts: StrToBool and StrToBoolDef.
#8
Posted 05 June 2007 - 03:37 PM
P.S. without table Boolean column.
jemiko@gmail.com
thanks
#9
Posted 05 June 2007 - 04:11 PM
Here is a one sample project with 3 checkbox columns and 3 different field types.
Please note that this sample require BDE to be installed.
db_checkbox.zip 3.67KB 15 downloads
Best regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#10
Posted 05 June 2007 - 08:12 PM
I want insert new column in the NextBDGrid, with myself: and not from table boolean column.
When I try insert new column from column editor, and set this parameters:
ValueChecked: true
ValueUnchecked: false
new cell don't work at click. I can't using cell cheking and uncheking at mouse cliking.
please, if you have any idea tell me or send me work example.
Thanks
#11
Posted 06 June 2007 - 12:20 AM
Maybe you have forgot to set coEditing flag in Column.Options to True ?
I hope that this is it.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#12
Posted 06 June 2007 - 11:18 AM
Maybe you have forgot to set coEditing flag in Column.Options to True ?
I hope that this is it.
regards
Yes,
coEditing flag in Column.Options to True...
#13
Posted 06 June 2007 - 11:41 AM
Maybe your and mine English are not compatible
Can you please write your post again, more detailed.
Thank you
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#14
Posted 06 June 2007 - 12:50 PM
====
1) FName
2) FPrice
====
if you don't Understand my, i can send you Exaple.
#15
Posted 06 June 2007 - 01:03 PM
You may use OnCellApply event for displaying checkboxes.
Add several checkbox columns and set ValueChecked of 4th column to "true" and ValueUnchecked to "false". Then add next code in OnApplyCell:
var Value: String);
begin
if ACol = 3 then
begin
Value := 'false'; // Value := 'true';
// here you may read NextDBGrid.Columns[x].Field and similar operations.
end;
end;
But, currently you can't edit it becuase grid automatically denie editing columns without Field attached.
Maybe something may be done in OnBeforeEdit event. This event will return ACol and ARow parameters to tell you which cell is started editing.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#16
Posted 06 June 2007 - 02:42 PM
I need you'r help
#17
Posted 06 June 2007 - 02:53 PM
Here is a example similar to previous one, but with one new CheckBox column without Field assigned:
dbcheckbox_column.zip 371.99KB 22 downloads
How it works:
1) Cell get value from OnCellApply event, so we don't need a Field attached.
2) After we click on Checkbox, OnAfterEdit event is called and here we may update some data (change other Field, run SQL query...)
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#18
Posted 06 June 2007 - 03:11 PM
thank you, for code examle. I run it and I also see new comlumn in grig,but when I try click on cell I see MessageBox with ACol and ARow values, and cell after my click is not cheked, why? Please, include this function (cell cheking) in your exsample and send me again.
Thanks a lot.
#19
Posted 06 June 2007 - 03:28 PM
This event you need to use to do some action after user click on checkbox. In this event you may read ACol and ARow parameters and then do some action.
For example:
After user click on checkbox, you will store this row into TList, and after user click on OK (Apply) button, this rows may be processed.
Also, after user click on checkbox, you may delete this row or do some other action too.
--
All this need to be done manualy (virtualy) because NextDBGrid doesn't have cells as NextGrid.
regards
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#20
Posted 23 November 2011 - 10:57 AM
You may have any kind of Field for checkbox column, all you have to know is that:
if Field.AsString = ValueChecked ----> checkbox will be shown and checked.
if Field.AsString = ValueUnchecked ----> checkbox will be shown but unchecked.
otherwise cell will be empty.
regards
For this is a rather old question - a DB boolean column has three possible options: True/False/DBNull.
In current version False and DBNull are both shown as unchecked - so it doesn't behave like the way you stated before.
(If I display the same column as text, the DBNull shows an empty string.)
Is it possible to change this behaviour?
EDIT: It is. There is a fix for unicode that broke the old behaviour.
New code / NxDBDisplays.pas:
procedure TNxDBCheckBoxColumnDisplay.Paint; var Value: Boolean; begin with Column as TNxDBCheckBoxColumn do begin if WideSameText(AsString, ValueChecked)then Value := True else if WideSameText(AsString, ValueUnchecked) then Value := False else Exit; DrawCheckBoxState(Self.ClientRect, Value, False, False); end; end;
This will not draw a checkbox if the value is different from Checked/Unchecked values.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users