Jump to content


Photo

Checkbox in NextDBGrid


  • Please log in to reply
23 replies to this topic

#1 larsf

larsf
  • Members
  • 11 posts

Posted 11 February 2007 - 07:48 PM

Hi,
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 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 12 February 2007 - 08:26 AM

Hello Larsf,

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
boki@bergsoft.net | LinkedIn Profile
--
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 larsf

larsf
  • Members
  • 11 posts

Posted 13 February 2007 - 10:30 AM

Hi,

I have try this:

CODE
procedure TForm1.NextDBGrid1ColumnCreate(Sender: TObject; Field: TField;
  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 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 13 February 2007 - 10:37 PM

Hi,

Very strange. Try to change line:

CODE
if Field.FieldName = 'Fertig' then ColumnClass := TNxDBCheckBoxColumn;


into

CODE
if Field.FieldName = 'Fertig' then ColumnClass := TNxDBTextColumn;


to read values from field.

Then you may set ValueChecked and ValueUnchecked again.

regards
boki@bergsoft.net | LinkedIn Profile
--
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 larsf

larsf
  • Members
  • 11 posts

Posted 14 February 2007 - 11:54 AM

Hi,

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 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 15 February 2007 - 04:46 AM

Hello,

Probably localization settings have change it.

regards
boki@bergsoft.net | LinkedIn Profile
--
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 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 15 February 2007 - 12:09 PM

F.Y.I Here a piece of code showing how BoolToStr can be changed into working with other strings like the german ones:

CODE
var b : boolean;

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.
G.W. van der Vegt

#8 Dito

Dito
  • Members
  • 7 posts

Posted 05 June 2007 - 03:37 PM

Please Send me Works Exapmle, or Write this. How paste checkbox column to NextBDGrid.
P.S. without table Boolean column.

jemiko@gmail.com
thanks

#9 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 05 June 2007 - 04:11 PM

Hello,

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.

Attached File  db_checkbox.zip   3.67KB   15 downloads

Best regards
boki@bergsoft.net | LinkedIn Profile
--
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 Dito

Dito
  • Members
  • 7 posts

Posted 05 June 2007 - 08:12 PM

Boki, this example is not what i need.
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 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 June 2007 - 12:20 AM

Hello Dito,

Maybe you have forgot to set coEditing flag in Column.Options to True ?

I hope that this is it.

regards
boki@bergsoft.net | LinkedIn Profile
--
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 Dito

Dito
  • Members
  • 7 posts

Posted 06 June 2007 - 11:18 AM

QUOTE (Boki (Berg) @ Jun 6 2007, 12:20 AM) <{POST_SNAPBACK}>
Hello Dito,

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...
sad.gif

#13 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 June 2007 - 11:41 AM

Hello Dito,

Maybe your and mine English are not compatible sad.gif

Can you please write your post again, more detailed.

Thank you
boki@bergsoft.net | LinkedIn Profile
--
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 Dito

Dito
  • Members
  • 7 posts

Posted 06 June 2007 - 12:50 PM

Sorry for my English I'm need Insert new Boolean Column in design-time, with my NextBDGrid, but my Table don't contained boolean column. Table Column:
====
1) FName
2) FPrice
====
if you don't Understand my, i can send you Exaple.

#15 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 June 2007 - 01:03 PM

Hello Dito,

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:

CODE
procedure TForm1.NextDBGrid1ApplyCell(Sender: TObject; ACol, ARow: Integer;
  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
boki@bergsoft.net | LinkedIn Profile
--
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 Dito

Dito
  • Members
  • 7 posts

Posted 06 June 2007 - 02:42 PM

Please send my Work example.
I need you'r help sad.gif

#17 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 June 2007 - 02:53 PM

Hello Dito,

Here is a example similar to previous one, but with one new CheckBox column without Field assigned:

Attached File  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
boki@bergsoft.net | LinkedIn Profile
--
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 Dito

Dito
  • Members
  • 7 posts

Posted 06 June 2007 - 03:11 PM

Hello Boki,
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 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 06 June 2007 - 03:28 PM

Hello Dito,

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
boki@bergsoft.net | LinkedIn Profile
--
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 tarnschaf

tarnschaf
  • Members
  • 14 posts

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