Recent

Author Topic: how to sort rows in db grid ?  (Read 6291 times)

grexos

  • Newbie
  • Posts: 4
how to sort rows in db grid ?
« on: July 22, 2008, 01:38:26 pm »
I have application working with dfb files. after insert row in database, dbgrid show it as last row.

i need sort rows by one field can you help me pls  

thx

andrea

  • Newbie
  • Posts: 4
Re: how to sort rows in db grid ?
« Reply #1 on: July 23, 2008, 09:55:05 am »
Quote from: "grexos"
I have application working with dfb files. after insert row in database, dbgrid show it as last row.

i need sort rows by one field can you help me pls  

thx


- - - - - - - -- - - - -- - - - - - -- - - - - - - --
1) insert index in the table dbf in "INDEXDEF"
    ADD....
    indexFile = ID1 (or your name of index)
    sortField = (name of campo es. ID_CUSTOMER)

    es ID1 , ID2, ID3, ... IDn (INDEX OF SORT RECORD)

2) THE COMMAND IS:
    MyTable.IndexName:='IDn';

grexos

  • Newbie
  • Posts: 4
how to sort rows in db grid ?
« Reply #2 on: July 23, 2008, 02:56:34 pm »
thx for reply but can you write full example ?

my table is created as this:

  With DBA do
    begin
    Close;
    with FieldDefs do
      begin
      Clear;
       Add('ISRC',ftString,20);
       Add('NAZOV',ftString,64);
      end;
    TableName:=AFileName;
    CreateTable;
    Exclusive := true;
    Open;
    end;

and i need sort it by "NAZOV"

DougNettleton

  • Jr. Member
  • **
  • Posts: 84
how to sort rows in db grid ?
« Reply #3 on: July 23, 2008, 05:59:56 pm »
The following code works for me:

create a table with two indexes ...  

  Dbf1.FilePath:= 'data/';
  Dbf1.TableLevel := 4;
  Dbf1.Exclusive := True;
  Dbf1.TableName:='testdata.dbf';
  with Dbf1.FieldDefs do begin
    Add('Id', ftString, 4, True);
    Add('Name', ftString, 30, True);
  end;
  Dbf1.CreateTable;
  Dbf1.Open;
  Dbf1.AddIndex('custid', 'Id', [ixPrimary, ixUnique]);
  Dbf1.AddIndex('custname', 'Name', [ixCaseInsensitive]);
  Dbf1.Close;

Open the table, select an index, go to first record

  Dbf1.FilePath:= 'data/';
  Dbf1.TableLevel := 4;
  Dbf1.Exclusive := True;
  Dbf1.TableName:='testdata.dbf';
  Dbf1.Open;
  Dbf1.IndexName:='custid';
  Dbf1.First;

Toggle between indexes

  if Dbf1.IndexName = 'custid' then
    Dbf1.IndexName := 'custname'
  else
    Dbf1.IndexName:='custid';

HTH,

Doug

grexos

  • Newbie
  • Posts: 4
how to sort rows in db grid ?
« Reply #4 on: July 24, 2008, 11:00:38 am »
oki its works. I defined index on field NAZOV a after open used it ;) thx very much

 

TinyPortal © 2005-2018