sw4all 0 Posted August 15, 2021 (edited) Hello to everybody. I need to add a button to each cell and use one click function. Unfortunately I get an error Access violation at address ... Thank you all. Daniel public { Public declarations } procedure btnChangeSClick(Sender: TObject); ... ... procedure TfrmMain.btnChangeSkupinaClick(Sender: TObject); begin frmSelectS.gridName := 'TEST'; frmSelectS.ShowModal; end; procedure TfrmMain.grid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var Field: TField; fixRect : TRect; btnChangeS: TButton; begin Field := Column.Field; if (Column.Index = 0) then begin try btnChangeS.Create(grid1); btnChangeS.Parent := grid1; btnChangeS.Visible := True; btnChangeS.Caption := '...'; btnChangeS.Width := 25; btnChangeS.Height := (Rect.Bottom - Rect.Top) - 2; btnChangeS.Left := (Rect.Left + Rect.Width) - (btnChangeS.Width +1); btnChangeS.Top := Rect.Top + 1; btnChangeS.OnClick := btnChangeSClick; grid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); except On E: exception do begin ShowMessage(E.Message); end; end; end; end; Edited August 15, 2021 by sw4all Share this post Link to post
Pat Foley 51 Posted August 15, 2021 Quote btnChangeS.Create(grid1); btnChangeS := TButton.Create(grid1); 1 Share this post Link to post
sw4all 0 Posted August 15, 2021 2 minutes ago, Pat Foley said: btnChangeS := TButton.Create(grid1); Yes. Thank you so much for your quick help. Everything is working. Share this post Link to post
sw4all 0 Posted August 15, 2021 (edited) I see one more error and that is that the procedure still creates more and more buttons. Please look in the upper left corner. Sample video. Debut 2021-08-15 17_57_46.mp4 Edited August 15, 2021 by sw4all Share this post Link to post
Lajos Juhász 293 Posted August 15, 2021 46 minutes ago, sw4all said: I see one more error and that is that the procedure still creates more and more buttons. It's not an error, it's how you've coded to create a new button in every paint event. Instead of that I would use the inbuild feature of the dbgrid. On you column set ButtonStyle to cbsEllipsis then you can place your in the OnEditButtonClick event of the grid. 1 Share this post Link to post
sw4all 0 Posted August 15, 2021 (edited) 26 minutes ago, Lajos Juhász said: It's not an error, it's how you've coded to create a new button in every paint event. Instead of that I would use the inbuild feature of the dbgrid. On you column set ButtonStyle to cbsEllipsis then you can place your in the OnEditButtonClick event of the grid. Yes thank you. The problem is that dgEditing will not be enabled, so the button will not appear. Oh, just set DBGrid readOnly: = True; Edited August 15, 2021 by sw4all Share this post Link to post
sw4all 0 Posted August 15, 2021 (edited) Is there any way for the button to still be visible, not only when a cell is selected? So that the user can see which cells he can edit. Edited August 15, 2021 by sw4all Share this post Link to post