Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 08-16-2005, 05:37 AM
FourARSEDSheep FourARSEDSheep is offline
Member
 
Join Date: Mar 2002
Posts: 58
Default Sorting DBGrid with TDbf

Is this possible? I'm using TDbf for a small databasing app, and i want to be able to sort the data in a DBGrid by clicking on the titles. All the examples I've seen of sorting data in a DBGrid seem to be for apps using TQuery etc - whereas I dont have this component. I simply have:

TDbf -> DataSource -> DBGrid

I take it that the datasorting will be something to do with the TDbf rather than anything else?

Cheers

--Tom
Reply With Quote
  #2  
Old 08-16-2005, 05:52 AM
afx2029 afx2029 is offline
Senior Member
 
Join Date: Jul 2004
Posts: 478
Default RE: Sorting DBGrid with TDbf

what backend ar eyou using? SQL based (MSSQL, Oracle, Interbase..), file based (Paradox, DBase, FoxPro...)...
Reply With Quote
  #3  
Old 08-16-2005, 05:53 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: Sorting DBGrid with TDbf

TDBF has the property IndexFieldName just as any TDataset descendent does. So, make sure all fields that are going to be sorted on, are indexed when you create your tables.

then use

procedure TfrmMain.DBGrid1TitleClick(Column: TColumn);
begin
if Column.Index = 0 then
MyTable.IndexFieldName:= ?
else
if Column.Index = 1 then
MyTable.IndexFieldName:= ?
etc
etc
end;

You can sort tables based on more than one field, by separating the fields with a semicolon

MyTable.IndexFieldName:= 'Field1;Field2';



If this helps, please accept as answer!

Thanks!

UnSysApps
Reply With Quote
  #4  
Old 01-13-2011, 12:38 PM
Donovan Donovan is offline
Senior Member
 
Join Date: Jan 2011
Posts: 150
Send a message via Skype™ to Donovan
Default

Douglas thank you so much, I have been searching for this for ages!

One more thing though, is it possible to decide whether to sort Ascending or decending?

Looking forward to your reply.
Reply With Quote
  #5  
Old 09-16-2011, 03:56 AM
Zei54Nol Zei54Nol is offline
Junior Member
 
Join Date: Sep 2011
Posts: 8
Default

you create your tables.

Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:49 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.