#1 2012-01-18 10:22:50

lele9
Member
Registered: 2011-10-28
Posts: 170

lookup with TAdvGridDropDown

Hi,
i try to set a TAdvGridDropDown to lookup a TSQLRecord'ID value in another TSQLRecord.

i use something like this

ElencoGroupRight := Client.MultiFieldValues(TSQLAuthGroup, '');
GrigliaGroupRight := TSQLTableToGrid.Create(GRIDGroupRight.Grid, ElencoGroupRight, Client);

and the grid is correctly populated but i cant select any row.

while if i populate the grid by hand like the tms example

GRIDGroupRight.Grid.RowCount := 8;
GRIDGroupRight.Grid.ColCount := 2;
GRIDGroupRight.Grid.Cells[0,0] := 'Number';
GRIDGroupRight.Grid.Cells[1,0] := 'Name';

GRIDGroupRight.Grid.Rows[1].CommaText := '1,Monday';
GRIDGroupRight.Grid.Rows[2].CommaText := '2,Tuesday';
GRIDGroupRight.Grid.Rows[3].CommaText := '3,Wednesday';
GRIDGroupRight.Grid.Rows[4].CommaText := '4,Thursday';
GRIDGroupRight.Grid.Rows[5].CommaText := '5,Friday';
GRIDGroupRight.Grid.Rows[6].CommaText := '6,Saturday';
GRIDGroupRight.Grid.Rows[7].CommaText := '7,Sunday';

the AdvGridDropDown work perfectly.

Can you help me?
Thanks a lot and excuse for my bad english,
Emanuele.

Offline

#2 2012-01-18 12:43:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,667
Website

Re: lookup with TAdvGridDropDown

I think TAdvGridDropDown override some events of the Grid components.
So TSQLTableToGrid does not work as expected.

In fact, TSQLTableToGrid is aimed to work only with a plain standard TDrawGrid, not a grid embedded inside another component.
You can use the GRIDGroupRight.Grid.Rows[] or Cells[] properties to populate the TAdvGridDropDown  grid from the data retrieved, with a for .... loop.

It will be slower, but it will work:

GRIDGroupRight.Grid.RowCount := ElencoGroupRight.RowCount+1;
GRIDGroupRight.Grid.ColCount := 2;
GRIDGroupRight.Grid.Cells[0,0] := 'Number';
GRIDGroupRight.Grid.Cells[1,0] := 'Name';
for i := 1 to ElencoGroupRight.RowCount do 
begin
  GRIDGroupRight.Grid.Cells[0,i] := ElencoGroupRight.GetString(i,0);
  GRIDGroupRight.Grid.Cells[1,i] := ElencoGroupRight.GetString(i,1);
end;

Of course, it could be a good idea to make this a global function, ready to be reused.

Online

#3 2012-01-18 15:05:40

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: lookup with TAdvGridDropDown

yes, i thinked about this solution.
and write a function integrated in the framework can be a good idea?
thanks for the support,
Emanuele.

Offline

#4 2012-01-18 15:53:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,667
Website

Re: lookup with TAdvGridDropDown

Good idea.

I've added a new FillStringGrid() function, ready to fill a regular TStringGrid.

See http://synopse.info/fossil/info/2af8e888d3

Online

#5 2012-01-18 15:54:56

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: lookup with TAdvGridDropDown

a simple and rapid version of the procedure...maybe can help for other user.
thanks again!

procedure loadLookupGrid(var LookupGrid: TAdvGridDropDown; Tabella: TSQLRecordClass; Client: TSQLRestClientURI);
var Elenco: TSQLTableJSON;
    I: Integer;
    J: Integer;
begin
   Elenco := Client.MultiFieldValues(Tabella, '');
   LookupGrid.Columns.Clear;
   LookupGrid.Grid.FloatFormat := '%.0f';
   LookupGrid.UseItems := False;
   LookupGrid.BeginUpdate;
   LookupGrid.Grid.RowCount := Elenco.RowCount+1;
   LookupGrid.Grid.ColCount := Elenco.FieldCount;
   for I := 0 to Elenco.FieldCount-1 do
   begin
      LookupGrid.Grid.Cells[I,0] := Tabella.RecordProps.Fields[i].ShortName;
   end;
   for J := 0 to Elenco.RowCount do
   begin
      for I := 0 to Elenco.FieldCount-1 do
      begin
         LookupGrid.Grid.Cells[i,j] := Elenco.GetString(j,i);
      end;
   end;
   LookupGrid.EndUpdate;
end;

Offline

#6 2012-01-18 16:03:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,667
Website

Re: lookup with TAdvGridDropDown

Thanks for the code.

You do not free the Elenco instance - this may lead into huge memory leak.

Add a "try ... finally Elenco.Free end" block in your code.

Online

#7 2012-01-18 16:07:15

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: lookup with TAdvGridDropDown

yes i forget sorry!

Offline

Board footer

Powered by FluxBB