| View previous topic :: View next topic |
| Author |
Message |
shivdasn Regular

Joined: 19 Jun 2005 Posts: 58 Location: India
|
Posted: Jun 22nd, 2005 10:59 AM Post subject: How to sort data in a DBGrid? |
|
|
Hi,
I have a form in my prog where there's a dbgrid control. now i need a combo box, which is populated with the column headers of the database on which the dbgrid is based. Now on the click event of this combobox the records of the dbgrid should be sorted according to the header selected in the combo box. How do i go about it?
Thanx in advance.... |
|
| Back to top |
|
more Newbie
Joined: 07 Jun 2005 Posts: 13
|
Posted: Jun 27th, 2005 04:21 AM Post subject: use sql |
|
|
sqls are very handy and powerful. i'll give you a sample and then adapt to your needs.
data1.recordsource = "select * from <table1> order by <field1.name>"
or if you are using a defined recordset
set rstRecord = "select * from <table1> order by <field1.name>"
the words enclosed are the specific name of your recordset and the fieldname. enclosed words are just sample table and fieldnames. |
|
| Back to top |
|
blackhd Newbie
Joined: 23 Jul 2005 Posts: 5
|
Posted: Jul 23rd, 2005 01:13 PM Post subject: |
|
|
in your combo, list down item according to the database column, then...
combo_click
dbgrid.col = combo.listindex
dbgrid.sort = 1 'to sort ascending
dbgrid.sort = 2 'to sort descending |
|
| Back to top |
|
|