We recently use the TAdvStringGrid for user input in our software.
For user-friendliness, we use nodes at different levels so that the user can open / close which input he wants to see.
However, we encounter problems when adding an edCombobox. Example code from the documentation sometimes succeeds / sometimes fails. Seems that with closed nodes the correct row / col is not always given in GetEditorProp / GetEditorType.
Combo data can differ from cell to cell.
code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
AdvGrid;
type
TForm1 = class(TForm)
Grid: TAdvStringGrid;
procedure GridGetEditorProp(Sender: TObject; ACol, ARow: Integer;
AEditLink: TEditLink);
procedure FormCreate(Sender: TObject);
procedure GridGetEditorType(Sender: TObject; ACol, ARow: Integer;
var AEditor: TEditorType);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
list1 = 'A-choose a;B-choose b;C-choose c';
list2 = 'yes;no;cancel';
list3 = 'white;black;red;blue;green;yellow';
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Grid.Cells[1, 1] := 'level 1';
Grid.Cells[1, 2] := 'list 1';
Grid.Cells[1, 3] := 'level 2';
Grid.Cells[1, 4] := 'list 2';
Grid.Cells[1, 5] := 'level 3';
Grid.Cells[1, 6] := 'list 3';
Grid.Options := Grid.Options + [goEditing];
Grid.AddNode(5, 2);
Grid.AddNode(3, 4);
Grid.AddNode(1, 6);
end;
procedure TForm1.GridGetEditorProp(Sender: TObject; ACol, ARow: Integer;
AEditLink: TEditLink);
var
slist: string;
begin
if ACol = 2 then
begin
Grid.ClearComboString;
case ARow of
2:
slist := list1;
4:
slist := list2;
6:
slist := list3;
else
slist := '';
end;
if slist <> '' then
begin
Grid.Combobox.Items.Delimiter := ';';
Grid.Combobox.Items.StrictDelimiter := true;
Grid.Combobox.Items.NameValueSeparator := '-';
Grid.Combobox.Items.DelimitedText := slist;
end;
end;
end;
procedure TForm1.GridGetEditorType(Sender: TObject; ACol, ARow: Integer;
var AEditor: TEditorType);
begin
if (ACol = 2) and (Grid.Combobox.Items.Count > 0) then
AEditor := edComboEdit
else
AEditor := edNormal;
end;
end.