Topic: Clickable Link column in tGrid?

Is it possible to have clickable link column/s in tGrid for URL /  Email addresses?

Adam
God... please help me become the person my dog thinks I am.

Re: Clickable Link column in tGrid?

Clickable URL/Email for first column,

procedure Form1_TableGrid1_OnCellClick (Sender: string; ACol, ARow: Integer);
begin
    if ACol=0 then
    if Pos('@', Form1.TableGrid1.Cells[ACol,ARow]) > 0 then
        OpenUrl('mailto:'+Form1.TableGrid1.Cells[ACol,ARow])
        else OpenUrl(Form1.TableGrid1.Cells[ACol,ARow]);
end;
Dmitry.

Re: Clickable Link column in tGrid?

Hi Dmitry,


Thank you very much..................
Truly appreciated........................


After trial and error (replacing @ with www for a URL), I think, I managed to have URL and Email links on separate columns:

procedure FORM2_TableGrid3_OnCellClick (Sender: string; ACol, ARow: Integer);
begin
  if ACol=1 then
  if Pos('www', Form2.TableGrid3.Cells[ACol,ARow]) > 0 then
     OpenUrl(Form2.TableGrid3.Cells[ACol,ARow]);

  if ACol=2 then
  if Pos('@', Form2.TableGrid3.Cells[ACol,ARow]) > 0 then
     OpenUrl('mailto:'+Form2.TableGrid3.Cells[ACol,ARow])
end;

If the above is incorrect, please correct.

Adam
God... please help me become the person my dog thinks I am.

Re: Clickable Link column in tGrid?

Link may be without 'www', better to use 'http' to check link.

Dmitry.

Re: Clickable Link column in tGrid?

DriveSoft wrote:

Link may be without 'www', better to use 'http' to check link.


Good point.
However, user may just type www.myvisualdatabase.com instead of c/p or type full url http://myvisualdatabase.com/index.html
Plus there are urls with https such as https://www.google.com


If possible best solution would be to include all 3 by making the following line to work:

if Pos('https' or 'http' or 'www', Form2.TableGrid3.Cells[ACol,ARow]) > 0 then
Adam
God... please help me become the person my dog thinks I am.

Re: Clickable Link column in tGrid?

if (Pos('http',  Form2.TableGrid3.Cells[ACol,ARow]) =1) or (Pos('www',  Form2.TableGrid3.Cells[ACol,ARow]) =1)  then
Dmitry.

Re: Clickable Link column in tGrid?

Thank you very much Dmitry................


Taking it bit further, I wanted apply couple more features to clickable linked URLs and Emails
♦ Coloring linked columns: Works fine
♦ Underlining linked items: Not working
♦ Changing mouse to crHandPoint when mouse moves over a linked item: Not working.


I tried the following but I think I couldn't get the syntax right except coloring part:

procedure FORM2_TableGrid3_OnChange (Sender: string); // Selected whole column Text Coloring
var  vc, vi: integer;
begin
  vc := FORM2.TableGrid3.rowcount-1;
  for vi := 0 to vc do
    begin
      FORM2.TableGrid3.cell[1,vi].textcolor := clblue;
      FORM2.TableGrid3.cell[2,vi].textcolor := clblue;
      FORM2.TableGrid3.cell[1,vi].FontStyle := Underlined;
    end;
end;

procedure FORM2_TableGrid3_OnMouseEnter (Sender: string);
var  vc, vi: integer;
begin
  vc := FORM2.TableGrid3.rowcount-1;
  for vi := 0 to vc do
    begin
      FORM2.TableGrid3.cell[1,vi].Cursor := crHandPoint;
      FORM2.TableGrid3.cell[2,vi].Cursor := crHandPoint;
    end;
end;
Adam
God... please help me become the person my dog thinks I am.

Re: Clickable Link column in tGrid?

change

FORM2.TableGrid3.cell[1,vi].FontStyle := Underlined;

to

FORM2.TableGrid3.cell[1,vi].FontStyle := fsUnderline;


You can change cursor only for whole column

FORM2.TableGrid3.Columns[0].Cursor := crHandPoint; 
Dmitry.

Re: Clickable Link column in tGrid?

Thank you very much for your kind help Dmitry.......................


I tried to add couple of lines to have cursor turns into handpoint only when there is a link item within a cell

procedure FORM2_TableGrid3_OnMouseEnter (Sender: string);
var ACol, ARow: Integer;
begin
if (Pos('http',  Form2.TableGrid3.Cells[ACol,ARow]) =1) or (Pos('www',  Form2.TableGrid3.Cells[ACol,ARow]) =1)  then
   begin
   FORM2.TableGrid3.Columns[1].Cursor := crHandPoint;
   end;

if Pos('@', Form2.TableGrid3.Cells[ACol,ARow]) > 0 then
   begin
   FORM2.TableGrid3.Columns[2].Cursor := crHandPoint;
   end;
end;

However, it didn't work as usual

Adam
God... please help me become the person my dog thinks I am.

Re: Clickable Link column in tGrid?

Your script is wrong, you can use it only in this way:

procedure Form1_TableGrid1_OnChange (Sender: string);
begin
   Form1.TableGrid1.Columns[0].Cursor := crHandPoint;
end;
Dmitry.