Lazarus

Programming => Operating Systems => Android => Topic started by: amartitegui on December 14, 2017, 05:11:03 pm

Title: Question...anyone know how to implement something like.. dbgrid ?
Post by: amartitegui on December 14, 2017, 05:11:03 pm
Hi, I would need to show some results in a grid.
something like 5 columns, scroll too.

Using LAMW at this moment...


Any good ideas? :)
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: jmpessoa on December 14, 2017, 08:35:52 pm

What about jGridView?
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: kwer on December 19, 2017, 08:09:05 am
@amartitegui : Good questions....but it's a hard task... you can see . /demos/GUI/AppActivityLauncherDemo1  ...use java to complete it.
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: c4p on December 19, 2017, 12:14:31 pm
I have tried to use jGridView but spacing and layout were an issue, I ended up using jListView instead.
Would really love jGridView to work similar to dbGrid, just having the cells beside each other would be a great help, spacing is currently too wide. Also option not to wrap text, truncate for example, would be ideal. :'(
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: amartitegui on December 19, 2017, 06:26:24 pm
I made it work thanks to Jmpessoa example.
really like how it works, and its quite flexible tool for data shoing...
Pitty cant change colours though.

Here I show you a mysql example.

Here  IS HOW i POPULATE THE GRID. (variable names should be yours):
NOTICE that I didn't write conetion data (mysqlconnector, sqlquery, transaction... that you shoud arrange before check if connected)
first, define col, row:
var
  row,col:integer;
begin
 
and later in procedure...

 if MySQL56Connection1.connected then begin
 
  jGridView1.clear;
  jGridView1.Columns:=8;
  row:=0;       
    try
      SQLQuery1.close;
      SQLQuery1.SQL.Text:=''YOUR QUERY')';
      SQLQuery1.active:=true;
      SQLQuery1.Open;
      while not SQLQuery1.EOF do
        begin
            jGridView1.AddRow(row);
            if not SQLQuery1.FieldByName('Id').isnull then jGridView1.Cells[0,row]:=SQLQuery1.FieldByName('Id').value;
            if not SQLQuery1.FieldByName('numeroPedido').isnull then jGridView1.Cells[1,row]:=SQLQuery1.FieldByName('numeroPedido').value;
            if not SQLQuery1.FieldByName('cliente').isnull then jGridView1.Cells[2,row]:=SQLQuery1.FieldByName('cliente').value;
            if not SQLQuery1.FieldByName('referenciaCliente').isnull then jGridView1.Cells[3,row]:=SQLQuery1.FieldByName('referenciaCliente').value;
            if not SQLQuery1.FieldByName('servida').isnull then jGridView1.Cells[4,row]:=SQLQuery1.FieldByName('servida').value;
            if not SQLQuery1.FieldByName('forrado_hoja').isnull then jGridView1.Cells[5,row]:=SQLQuery1.FieldByName('forrado_hoja').value;
            if not SQLQuery1.FieldByName('forrado_bastidor').isnull then jGridView1.Cells[6,row]:=SQLQuery1.FieldByName('forrado_bastidor').value;
            if not SQLQuery1.FieldByName('material_suelto').isnull then jGridView1.Cells[7,row]:=SQLQuery1.FieldByName('material_suelto').value;
          inc(row);
          SQLQuery1.Next;
        end;   
      SQLQuery1.Close;
    finally
    end;
   end;                   

Also, to make it easier and nicer to look. I use 2 grids. one above the other.
The first one I populate with a single row (as header).
That way when you need to repopulate data grid you can clear and dont need to repopulate headers. and Also, you can give it a different colour.
As example of header(of course, your header names):
procedure Tgps_sgtl_droid.preparagrid;
var
  row,col:integer;
begin
   with jGridView2 do begin
       Clear;
       Columns:=8;
       row:=0;
       jGridView2.AddRow(row);
       jGridView2.Cells[0,row]:='ID';
       jGridView2.Cells[1,row]:='PEDIDO';
       jGridView2.Cells[2,row]:='CLIENTE';
       jGridView2.Cells[3,row]:='REF CLIENTE';
       jGridView2.Cells[4,row]:='SERVIDA';
       jGridView2.Cells[5,row]:='FORR HOJA';
       jGridView2.Cells[6,row]:='FORR BASTI';
       jGridView2.Cells[7,row]:='MAT SUELTO';
   end;
end;       
set both grids parentwidth
and second one achored to header one, anchored below. with top margin=1 (header margin.bottom=1 too).

looks quite fine.
and is easy to repopulate.
hope it helps ;)
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: c4p on December 20, 2017, 06:52:47 am
Any screenshots?  :)
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: amartitegui on December 20, 2017, 07:57:30 am
sure.
There
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: c4p on December 20, 2017, 08:13:35 am
Very nice.
What spacing do you have set for the columns?
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: c4p on December 20, 2017, 08:30:29 am
Does anyone know how to set the columns to line up like this in jGridView:

Col1   Col2            Col3
1234  qwertyuiop  00000

Seems a straightforward question to ask but hard to do this currently with jGridView as far as I can see, tried with stretchmode, horz spacing, column size etc. Need col2 to be at least twice the size of col1, or at least virtually no horz spacing between columns.
Keep ending up with:

Col1             Col2               Col3
1234            qwertyuiop     00000

I think this needs a separate column size rather than a global one, or an autosize column width? unless I am overlooking something?
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: amartitegui on December 20, 2017, 05:09:05 pm
Dont know much about. sorry.
The aligning was fine in my example.
i may check further tomorrow and let u know what i find.
But dont really know. Sorry
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: jmpessoa on December 20, 2017, 05:42:47 pm
Hi c4p!

You can try:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(data2)data3');
  7. end;
  8.  

and:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(Part1|Part2)data3');
  7. end;
  8.  
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: c4p on December 21, 2017, 12:27:37 am
Thanks jmpessoa, I was referring to the jGridView, it does not have the SetDelimiter method.
I was looking for a way to set each column width manually (rather than using the global column size of SetColumnWidth) and would use SetHorizontalSpacing to allow for spacing between each.
This would mean more work to the jGridView component, unless I have overlooked a method already available?
Thank you again jmpessoa for all your work on LAMW.

Hi c4p!

You can try:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(data2)data3');
  7. end;
  8.  

and:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(Part1|Part2)data3');
  7. end;
  8.  
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: Thyphoon on April 02, 2020, 03:47:36 pm
@amartitegui

I´m trying to do exactly what you did in your example, but I hot this error:

E/libcontrols.so(22622): EInOutError: Can not load DB-Lib client library "libsybdb.so". Check your installation.

can you tell me how did you go about this?

Thanks!
Title: Re: Question...anyone know how to implement something like.. dbgrid ?
Post by: Thyphoon on April 06, 2020, 01:37:28 pm
Hi jmpessoa!

How can I add a 4th column? to this example?

Hi c4p!

You can try:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(data2)data3');
  7. end;
  8.  

and:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    jListView1.TextAlign := alCenter;
  4.    jListView1.ItemLayout := layText;
  5.    jListView1.Add('col1(col2)col3');
  6.    jListView1.Add('data1(Part1|Part2)data3');
  7. end;
  8.  
TinyPortal © 2005-2018