Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Apr 27, 2000



Application Security Testing: An Integral Part of DevOps

Sort DBGrid Contents With Recordset Refresh

It's often useful to sort a DBGrid field in either descending or ascending order. You do this by using the HeadClick event and the DataField property of columns. You must change the query string (Qry) with one of your own (be sure it contains the code in bold):
Private Sub DBGrid1_HeadClick(ByVal ColIndex As Integer)
	Dim Qry as string
	Qry = "SELECT * FROM MyTable WHERE Key='" _
		& txtKey & "' "
	Qry = Qry & "ORDER BY " & _
		DBGrid1.Columns(ColIndex).DataField _
		& " " & DBGrid1.Tag
	data1.RecordSource = Qry
	'toggle ASC and DESC keywords
	If DBGrid1.Tag = "ASC" Then DBGrid1.Tag _
		= "DESC" Else DBGrid1.Tag = "ASC"
End Sub
Juan Jose
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date