Recent

Author Topic: Issue with StringGrid when setting values using custom editors.  (Read 4320 times)

Hydexon

  • Full Member
  • ***
  • Posts: 170
Issue with StringGrid when setting values using custom editors.
« on: November 12, 2012, 06:30:45 pm »
Hello, you can help me with some issue with StringGrid when i setting value using custom editors in my case TFileNameEdit Control.

The situation this when i set an Editor in OnSelectEditor of the StringGrid with the following code:

Code: [Select]
procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  var Editor: TWinControl);
var
Re : TRect;
begin
   if (aCol =1) then begin
    if (aRow = 1) then begin
     Re := StringGrid1.CellRect(1,1);
     Re.Right:= (Re.Right -20);
     FileNameEdit1.BoundsRect := Re;

     StringGrid1.Cells[1,1]  :=FileNameEdit1.FileName;

     FileNameEdit1.Text := StringGrid1.Cells[1,1];
     Editor := FileNameEdit1;
     StringGrid1.SetFocus;
    end;                                           

And running it, and click the specified cell with sample value for example: myfile.txt the FileNameEdit1 don't appear the sample content. and when set a filename in FileNameEdit successfully appears the selected file and then leave the cell only appears the sample value that i set in Design-time, and again select the same cell appears the new text. Where is wrong?, please.

Thanks
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: Issue with StringGrid when setting values using custom editors.
« Reply #1 on: November 14, 2012, 11:28:30 pm »
The line  StringGrid1.Cells[1,1]  :=FileNameEdit1.FileName; is not necessary, in OnSelectEditor you only need to setup your editor, usually you update the editor with the content of cell so  FileNameEdit1.Text := StringGrid1.Cells[1,1]; should do it. What is missing it seems to be a way to update the grid when you choose a filename, for FilenameEdit component try OnAcceptFilename event, there you can do Stringgrid1.Cells[1,1] := Value (value is a parameter of OnAcceptFilename event), or if you allow manual editing try FilenameEdit's OnEditingDone event, etc.

Hydexon

  • Full Member
  • ***
  • Posts: 170
Re: Issue with StringGrid when setting values using custom editors.
« Reply #2 on: November 15, 2012, 12:52:53 am »
Ok, I appreciate your help!, i wish get this knowledge in the FreePascal & Lazarus but i'm still a noob.
Lazarus 1.0.4 Stable - FPC 2.6.0 - gtk2 | Linux Mint 14 Nadia | GNOME Shell 3.6.2 - Awesome | Intel x86 | HP Mini 1020-LA Netbook (old)
Lazarus 2.0.2 Stable - FPC 3.0.2 - Windows | Lenovo IdeaPad Y

 

TinyPortal © 2005-2018