0

hello is it possible for this code to display to a tdbgrid the search results in a list like style? (e.g. if i searched for john, all the data conataining john on a certain field will be displayed to the tdbgrid)

procedure Tspcb.dccolbtnClick(Sender: TObject);
begin
  zdctable.First;
  while not zdctable.EOF do
  begin
     if (zdctable.FieldByName('Collector').AsString = dcedit.Text)
     then begin
        cn.Caption := zdctable.FieldByName('Client_Name').AsString;
        col.Caption := zdctable.FieldByName('Collector').AsString;
        pay.Caption := zdctable.FieldByName('Daily_Payment').AsString;
        date.Caption := zdctable.FieldByName('Date').AsString;
        ddate.Caption := zdctable.FieldByName('Due_Date').AsString;
        id.Caption := zdctable.FieldByName('ID').AsString;
        la.Caption := zdctable.FieldByName('Loan').AsString;
        tc.Caption := zdctable.FieldByName('Total_Collectibles').AsString;
     end;

     ShowMessage('click ok for next profile');
     zdctable.Next;
  end;
end;
Chunk Chunk
  • 143
  • 6
  • 17
  • oic how can i make it happen to my code? will i need to change it all? – Chunk Chunk Apr 12 '13 at 15:47
  • Well I suggest you edit your question to ask "How to" rather than "Is it possible" – Jerry Dodge Apr 12 '13 at 15:47
  • 1
    I have a deja vue http://stackoverflow.com/questions/15956541/data-field-entry-searching/15962866#15962866 – bummi Apr 12 '13 at 15:48
  • well i thought it was a different question because i want to display the results to a db grid not to the labels, but if its against the rules im sorry i just thought it was right to ask this to another question @JerryDodge thanks for correcting my title. i was just a bit scared to post how to bec maybe someone will not answer my post because it sound like asking for too much. thanks – Chunk Chunk Apr 12 '13 at 15:51
  • @bummi The code is in fact the same, but the question is different. – Jerry Dodge Apr 12 '13 at 15:53
  • @JerryDodge can you guide me with the code regarding this post? – Chunk Chunk Apr 12 '13 at 16:18

1 Answers1

2

Just add a datasource, set property dataset to your dataset zdctable, add a DBgrid to your form and set the property datasource to the datasource.

The only piece of code you will need is in the OnchangeEvent of dcedit

procedure TForm3.dceditChange(Sender: TObject);
begin
   zdctable.FilterOptions:=[foCaseInsensitive]; // if wished
   zdctable.Filtered := Length(dcEdit.Text) > 0;
   if zdctable.Filtered then
      // zdctable.Filter := 'Collector like ' + QuotedStr('%' + dcEdit.Text + '%') 
      zdctable.Filter := 'Collector like ' + QuotedStr('*' + dcEdit.Text + '*') // Zeos- Syntax
   else  zdctable.Filter := '';
end;
bummi
  • 27,123
  • 14
  • 62
  • 101
  • thank you very much for helping me. will post later if i got it already. have a nice day. – Chunk Chunk Apr 12 '13 at 16:59
  • tried the code today but the dbgrid didnt display anything when i typed on the dedit, tried also putting it on a button: procedure TForm1.Button1Click(Sender: TObject); begin ztable1.FilterOptions:=[foCaseInsensitive]; // if wished ztable1.Filtered := Length(Edit1.Text) > 0; if ztable1.Filtered then ztable1.Filter := 'Collector like' + QuotedStr('% + Edit1.Text + %') else ztable1.Filter := ''; end; but still the dbgrid didnt displayed anything – Chunk Chunk Apr 14 '13 at 14:10
  • @ChunkChunk Zeos seen to use * as wildcard instead of %, I did an edit – bummi Apr 14 '13 at 15:03
  • oic that's why it didnt worked. after the edit it works now thanks alot :D – Chunk Chunk Apr 14 '13 at 23:45