Recent

Author Topic: Question...anyone know how to implement something like.. dbgrid ?  (Read 4133 times)

amartitegui

  • Jr. Member
  • **
  • Posts: 82
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? :)

jmpessoa

  • Hero Member
  • *****
  • Posts: 1504
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #1 on: December 14, 2017, 08:35:52 pm »

What about jGridView?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

kwer

  • New Member
  • *
  • Posts: 11
  • Its my fortune to have it, its my fate to lose it.
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #2 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.
----------------------------------
Duolong, please render me a fastest horse, I must  leave now!
----------------------------------

c4p

  • Jr. Member
  • **
  • Posts: 97
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #3 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. :'(
« Last Edit: December 19, 2017, 04:08:46 pm by c4p »
Lazarus 1.7 on W10 with LAMW rev.691

amartitegui

  • Jr. Member
  • **
  • Posts: 82
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #4 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 ;)
« Last Edit: December 19, 2017, 07:23:03 pm by amartitegui »

c4p

  • Jr. Member
  • **
  • Posts: 97
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #5 on: December 20, 2017, 06:52:47 am »
Any screenshots?  :)
« Last Edit: December 20, 2017, 08:13:01 am by c4p »
Lazarus 1.7 on W10 with LAMW rev.691

amartitegui

  • Jr. Member
  • **
  • Posts: 82
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #6 on: December 20, 2017, 07:57:30 am »
sure.
There

c4p

  • Jr. Member
  • **
  • Posts: 97
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #7 on: December 20, 2017, 08:13:35 am »
Very nice.
What spacing do you have set for the columns?
Lazarus 1.7 on W10 with LAMW rev.691

c4p

  • Jr. Member
  • **
  • Posts: 97
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #8 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?
« Last Edit: December 20, 2017, 08:32:41 am by c4p »
Lazarus 1.7 on W10 with LAMW rev.691

amartitegui

  • Jr. Member
  • **
  • Posts: 82
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #9 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

jmpessoa

  • Hero Member
  • *****
  • Posts: 1504
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #10 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.  
« Last Edit: December 20, 2017, 07:34:51 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

c4p

  • Jr. Member
  • **
  • Posts: 97
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #11 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.  
Lazarus 1.7 on W10 with LAMW rev.691

Thyphoon

  • New Member
  • *
  • Posts: 23
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #12 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!

Thyphoon

  • New Member
  • *
  • Posts: 23
Re: Question...anyone know how to implement something like.. dbgrid ?
« Reply #13 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