Recent

Author Topic: [SOLVED] How do I put text in a cbsButtonColumn  (Read 422 times)

Ever

  • Jr. Member
  • **
  • Posts: 71
[SOLVED] How do I put text in a cbsButtonColumn
« on: October 11, 2024, 04:21:02 am »
Greetings
I'm working with a dbgrid, and I would like to be able to add a text to the button that is drawn in each row when I configure a column in the ButtonStyle property as cbsButtonColumn. I appreciate any help you can give me since I don't know how to do it.
« Last Edit: October 13, 2024, 04:22:13 pm by Ever »

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: How do I put text in a cbsButtonColumn
« Reply #1 on: October 11, 2024, 11:56:35 pm »
Well, I know how to do that with a regular stringgrid.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  2.   aRect: TRect; aState: TGridDrawState);
  3. var
  4.   PT:TPoint;
  5. begin
  6.   if (aCol = 2) Then With Sender As TstringGrid Do
  7.    Begin
  8.       PT := arect.CenterPoint;
  9.       PT.Y := ARect.Top+1;
  10.       Canvas.Brush.Style:= bsClear;
  11.       Canvas.TextOut(PT.X, PT.Y, ARow.Tostring);
  12.    end;
  13. end;                                        
  14.  
  15.  

Maybe the DB version has a DrawCell.
The only true wisdom is knowing you know nothing

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: How do I put text in a cbsButtonColumn
« Reply #2 on: October 12, 2024, 08:39:37 am »
The simplest way is to DataSet you add a new field of type Calculated. Then in the OnCalcField event you add:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.SQLQuery1CalcFields(DataSet: TDataSet);
  2. begin
  3.   //same caption for all records  
  4.   SQLQuery1BtnCaptionCalcField.Text := 'Click me';
  5.   //or caption dependent on record
  6.   //SQLQuery1BtnCaptionCalcField.Text := 'Click me for ID: ' + query.FieldByName('ID').AsString;
  7. end;  
and then you assign this field to the FieldName property for the button column

Best regards / Pozdrawiam
paweld

Ever

  • Jr. Member
  • **
  • Posts: 71
Re: How do I put text in a cbsButtonColumn
« Reply #3 on: October 13, 2024, 04:21:57 pm »
Thanks to both of you, I used jamie code and it worked perfectly for me

 

TinyPortal © 2005-2018