Jump to content

Imagens in DBGrid


LogSistemas01

Recommended Posts

Hello people,

would I like to put an image of Fontawesome in the column of my grid?

I managed to do it by putting in SQL:
 

<i class = "far fa-edit"> </i>

It worked, but it doesn't make much sense to have this information in SQL.

I was wondering if there is another way?

If it is possible to put a button too, then on that button I would put fontawesome.
I searched the demos and didn't find it, I saw only one case with an image where canvas is used.
If there is an easier way it would be good to know.

And also if it is possible to make the HandPoint mouse cursor appear in the column with the image.


Thank you guys!

Link to comment
Share on other sites

11 hours ago, LogSistemas01 said:

it worked, but it doesn't make much sense to have this information in SQL.

Thank you guys!

 

You can use  OnGetText property  (DataSet Field) :

1. For a Persistent Field in this case "Etat" :


procedure TFraDemandes.MyDataSetEtatGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  if DisplayText then
  begin
    // Demandé
    if Sender.AsVariant = NULL then
       Text:= '<i class="fas fa-smile fa-2x " style=color:orange; ></i>'

    // Proposé
    else if Sender.AsInteger = 1 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:green; ></i>'

    // Absent
    else if Sender.AsInteger = 2 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:black; ></i>'

    // Traité
    else if Sender.AsInteger = 3 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:grey; ></i>';
  end;

end;

 

2.  On an Optional Field (not existing in the DataBase)  like column Edit and Trash :

You can Add theese two Fields on your SQL query :

  txtSQL:='Select TPL.IDPlaning,  .......' +
         _____________________________  
          '0 As Editer, 0 As Trash' +
         _____________________________    

          ' From TPLANINGS TPL ' +
          ' Join ....';
          
          

 

with the same technic :


procedure TFraDemandes.MyDataSetTrashGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  if DisplayText then Text:='<i class="fas fa-trash"></i>';
end;

 

 

 

1.png

Link to comment
Share on other sites

On 5/16/2020 at 5:31 AM, Abaksoft said:

 

You can use  OnGetText property  (DataSet Field) :

1. For a Persistent Field in this case "Etat" :



procedure TFraDemandes.MyDataSetEtatGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  if DisplayText then
  begin
    // Demandé
    if Sender.AsVariant = NULL then
       Text:= '<i class="fas fa-smile fa-2x " style=color:orange; ></i>'

    // Proposé
    else if Sender.AsInteger = 1 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:green; ></i>'

    // Absent
    else if Sender.AsInteger = 2 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:black; ></i>'

    // Traité
    else if Sender.AsInteger = 3 then
       Text:= '<i class="fas fa-smile fa-2x " style=color:grey; ></i>';
  end;

end;

 

2.  On an Optional Field (not existing in the DataBase)  like column Edit and Trash :

You can Add theese two Fields on your SQL query :


  txtSQL:='Select TPL.IDPlaning,  .......' +
         _____________________________  
          '0 As Editer, 0 As Trash' +
         _____________________________    

          ' From TPLANINGS TPL ' +
          ' Join ....';
          
          

 

with the same technic :



procedure TFraDemandes.MyDataSetTrashGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
  if DisplayText then Text:='<i class="fas fa-trash"></i>';
end;

 

 

 

1.png

Ah, I know this possibility, I used it only once, thanks for reminding me!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...