Recent

Author Topic: [EXAMPLE Bookmark as checkbox DBGrid]  (Read 568 times)

What I can do

  • Full Member
  • ***
  • Posts: 122
[EXAMPLE Bookmark as checkbox DBGrid]
« on: November 03, 2024, 02:06:51 pm »
OS:Windows 10@ 64
Lazarus 3.4
Project have bookmarks as checkboxes displayed as a column in a dbGrid.
This has not been resolved:
[Title change] How to set a checkbox in DBGrid linked to a BookmarkList

I weird things is I use Lazarus form to find it before and it was very simple but I crashed my code and now rebuilding I'm not able to find it.
I have all the DBGrid events in place and ready to respond but I don't have the checkboxes in the dbgrid.
I think the boxes are some sort of temp field made on the fly but I have not reproduced or found where to implement that.
I know I'm missing something simple.
« Last Edit: November 03, 2024, 07:54:14 pm by What I can do »

Sieben

  • Sr. Member
  • ****
  • Posts: 363
Re: DBGrid and Bookmark checkboxes
« Reply #1 on: November 03, 2024, 03:31:18 pm »
Do you mean this one?
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

What I can do

  • Full Member
  • ***
  • Posts: 122
Re: DBGrid and Bookmark checkboxes
« Reply #2 on: November 03, 2024, 04:20:19 pm »
Thanks for the Reply Seiben,
but Trust me, I am very good at removing and reinstalling Lazarus
the code example came from this Lazarus Form
Here is what I am looking for;
DBGrid has two DB columns showing the fields as string
I am wanting to add a third field/or temp field/or column that is of boolean
and furthermore that field is of info data form the Bookmark for each record
Need a simply click of the bookmark field to toggle the bookmark of that record

Sieben

  • Sr. Member
  • ****
  • Posts: 363
Re: DBGrid and Bookmark checkboxes
« Reply #3 on: November 03, 2024, 04:26:46 pm »
Please follow the link I gave you, it's all set out there. Has nothing to do with removing or reinstalling Lazarus
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7


What I can do

  • Full Member
  • ***
  • Posts: 122
Re: DBGrid and Bookmark checkboxes
« Reply #5 on: November 03, 2024, 04:49:53 pm »
well DUH!
the "this one?" comes up normal font on my monitor
my bad
 I am sorry for that.

What I can do

  • Full Member
  • ***
  • Posts: 122
Re: DBGrid and Bookmark checkboxes
« Reply #6 on: November 03, 2024, 07:53:16 pm »
UPDATE info
{ checkbox for bookmark}

1) Select the DBGrid [Right-Click] to popup Chose "EditColumns..."
2) Popup window (Editing EBGrid.Columns[0]...) below title bar find  and click the [Add] button
3) Notice in (Fetch Labels) listbox a new line appears as "0 -Tile" select that line
4)  IDE (Properties [(filter)                       ]) window notice the  "Properties" tab is selected
5) Just me but set
     a. ButtonStyle | cbsCheckboxColumn
     b. Title .Alignment   | taCenter
               ..Caption      | Pick
              ...Font . Style | [fsBold]
    c.Width | 40

  {NOTE: all other dbcolmuns will load as normal with the ".Open" command
               or free to set your own configuration}

6)  Close popup window (Editing EBGrid.Columns[0]...)  and as DBGrid is selected
7) Click the "Events" tab set these events
          a. OnCellClick  |  DBGrid1CellClick
          b. OnUserCheckboxState  |  DBGrid2UserCheckboxState

8 ) IDE (Source Editor) window  code these events
 
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1CellClick(Column: TColumn);
  2.  begin
  3.    if Column.Index=0 then
  4.       RecList.CurrentRowSelected := not RecList.CurrentRowSelected;
  5.  end;
  6.  
  7.  
  8. procedure TForm1.DBGrid1UserCheckboxState(sender: TObject; column: TColumn; var AState: TCheckboxState);
  9. begin
  10.   if RecList.CurrentRowSelected then
  11.     AState := cbChecked
  12.   else
  13.     AState := cbUnchecked;
  14. end;
  15.  
  16. procedure TForm1.FormCreate(Sender: TObject);
  17. begin
  18.   RecList := TBookmarkList.Create(DbGrid1);
  19. end;
  20.  
  21. procedure TForm1.FormDestroy(Sender: TObject);
  22. begin
  23.   RecList.Free;
  24. end;
  25.  
suggest reading through linked literature

Special thanks goes to member [Sieben]

 

TinyPortal © 2005-2018