Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting

Post new topic   Reply to topic
How to sort data in a DBGrid?
View previous topic :: View next topic  
Author Message
shivdasn
Regular


Joined: 19 Jun 2005
Posts: 58
Location: India

PostPosted: Jun 22nd, 2005 10:59 AM    Post subject: How to sort data in a DBGrid? Reply with quote

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
View user's profile Send private message Send e-mail MSN Messenger
more
Newbie


Joined: 07 Jun 2005
Posts: 13

PostPosted: Jun 27th, 2005 04:21 AM    Post subject: use sql Reply with quote

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
View user's profile Send private message
blackhd
Newbie


Joined: 23 Jul 2005
Posts: 5

PostPosted: Jul 23rd, 2005 01:13 PM    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic