Recent

Author Topic: Howto for using editors in TStringGrid  (Read 10692 times)

RainerHamann

  • New member
  • *
  • Posts: 8
Howto for using editors in TStringGrid
« on: August 02, 2006, 08:37:05 pm »
I want to convert a Delphi project to Lazarus and I need a grid component with different editors for different columns. TStringGrid seems to be okay for my project, but I get runtime errors when I'm selecting a second cell with an editor. The first allways works fine. Best for me would be an example application for using editors in TStringGrid.

jesusr

  • Sr. Member
  • ****
  • Posts: 470
RE: Howto for using editors in TStringGrid
« Reply #1 on: August 02, 2006, 09:20:20 pm »
As soon as I get some time I will write about it in the wiki.

What kind of editors do you need?, atm stringgrid has some editors built in, a std stringeditor, a picklist and button cell editor.

RainerHamann

  • New member
  • *
  • Posts: 8
Howto for using editors in TStringGrid
« Reply #2 on: August 02, 2006, 09:39:51 pm »
That's all I need at the moment. My problem are runtime errors at the second selection of a cell (first is okay).

Using a StringGrid without any additional events does not show any editor, so I tried the OnSelectCell event to show the editor.

Schueler is the stringgrid designed with the designer.


procedure TForm1.SchuelerSelectCell(Sender: TObject; Col, Row: Integer;var CanSelect: Boolean);
var
   r : TRect;
begin
     r := Schueler.CellRect(Col, Row);
     Schueler.Editor.Top := r.Top;
     Schueler.Editor.Left := r.Left;
     Schueler.Editor.Width := r.Right - r.Left;
     Schueler.Editor.Height := r.Bottom - r.Top;
     Schueler.Editor.Text := Schueler.Cells[Col, Row];
     Schueler.Editor.Show;
     Schueler.Editor.SetFocus;
end;

RainerHamann

  • New member
  • *
  • Posts: 8
Howto for using editors in TStringGrid
« Reply #3 on: August 02, 2006, 09:41:14 pm »
That's all I need at the moment. My problem are runtime errors at the second selection of a cell (first is okay).

Using a StringGrid without any additional events does not show any editor, so I tried the OnSelectCell event to show the editor.

Schueler is the stringgrid designed with the designer.


procedure TForm1.SchuelerSelectCell(Sender: TObject; Col, Row: Integer;var CanSelect: Boolean);
var
   r : TRect;
begin
     r := Schueler.CellRect(Col, Row);
     Schueler.Editor.Top := r.Top;
     Schueler.Editor.Left := r.Left;
     Schueler.Editor.Width := r.Right - r.Left;
     Schueler.Editor.Height := r.Bottom - r.Top;
     Schueler.Editor.Text := Schueler.Cells[Col, Row];
     Schueler.Editor.Show;
     Schueler.Editor.SetFocus;
end;

jesusr

  • Sr. Member
  • ****
  • Posts: 470
Howto for using editors in TStringGrid
« Reply #4 on: August 02, 2006, 10:09:32 pm »
In a grid without custom columns (see columns property objectinspector) you could use one of the built in editors by changing "editor" var parameter in grid's OnSelectEditor event handler which is called for every editable cell,  something like:

  if (Row=2)and(Col=2) then
     Editor := grid.EditorByStyle(TheStyle);

where TheStyle is one of: cbsAuto, cbsEllipsis, cbsNone, cbsPickList, cbsCheckboxColumn

but cbsCheckboxColumn is only implemented dbgrid currently.

In this handler you should do any setup like for example filling the picklist with values appropiated to the cell, column or row.

Positioning  and sizing is automatic.

if you want your editor always visible (which I get from your editor.show; editor.setfocus) use grid option goAlwaysShowEditor

if you want to use a editor apart from the grid's built in editors, I will have to write that in the wiki, but that will have to wait a little.

RainerHamann

  • New member
  • *
  • Posts: 8
Howto for using editors in TStringGrid
« Reply #5 on: August 02, 2006, 10:18:31 pm »
Thanks!

 

TinyPortal © 2005-2018