4 Replies - 29868 Views - Last Post: 12 April 2010 - 11:16 AM Rate Topic: -----

#1 Don K O'Tay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-March 07

Datagrid sort columns by user

Posted 21 March 2007 - 05:12 AM

I have searched for hours to find help in sorting columns in a datagrid. I mean by user, not at design time.
As far as I can see, none of the three grids available to vb6 have a sort facility to change columns to Ascending or Descending as in msAccess.
I think vb.Net has a method by clicking on column headers, but I use the old vb6.
Am I wasting my own and helpful advisers time by my efforts?
I will try something else if there is no way to sort my columns with my version of visual basic.
I wou ld rather not.

Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid sort columns by user

#2 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: Datagrid sort columns by user

Posted 21 March 2007 - 10:01 PM

in the _Click event capture the colum name then
re-sort the recordset using a SQL command similar to . . .

datPrimaryRS.RecordSource = "select All from My DataSource Sort By " & desiredSort
datPrimaryRS.Refresh

this will achieve your desired results
Was This Post Helpful? 0
  • +
  • -

#3 bizchaplain  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 25-May 07

Re: Datagrid sort columns by user

Posted 25 May 2007 - 10:50 AM

Since the datagrid is populated from a recordset, here is the solution I've used. It may not be the best, and I'm open to ideas.
Given recordset "rs" and a field name of "xyz", the Datagrid sorts when you do the following:
rs.Sort = "xyz ASC" or rs.Sort = "xyz DESC"
(same as the ORDER BY clause)

I've put this example into a datagrid's HeadClick event to sort a column, and to toggle its direction on a second click:
	If ColIndex = prevSortCol Then
		If blnSortAsc Then
			strSort = strColumnName & " DESC "
			blnSortAsc = False
		Else
			strSort = strColumnName & " ASC "
			blnSortAsc = True
		End If
	Else
		strSort = strColumnName & " ASC"
		prevSortCol = ColIndex
		blnSortAsc = True
	End If
	rs.Sort = strSort
	With dg
		.Refresh
	End With


Some of the variables are Form-level, and you will want to populate them.
Charles
Was This Post Helpful? 1

#4 Don K O'Tay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-March 07

Re: Datagrid sort columns by user

Posted 04 January 2010 - 05:43 AM

View PostKeyWiz, on 21 Mar, 2007 - 09:01 PM, said:

in the _Click event capture the colum name then
re-sort the recordset using a SQL command similar to . . .

datPrimaryRS.RecordSource = "select All from My DataSource Sort By " & desiredSort
datPrimaryRS.Refresh

this will achieve your desired results




Dear 'Key Wiz'

ref my question 21 mar 2007 post = 210725 - Along time ago!

Many thanks for your reply.

I was too impatient and did not give time for replies. I then went down a different route.

Yours Don K O'tay
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Tim*


Reputation:

Re: Datagrid sort columns by user

Posted 12 April 2010 - 11:16 AM

View PostDon K O, on 04 January 2010 - 04:43 AM, said:

View PostKeyWiz, on 21 Mar, 2007 - 09:01 PM, said:

in the _Click event capture the colum name then
re-sort the recordset using a SQL command similar to . . .

datPrimaryRS.RecordSource = "select All from My DataSource Sort By " & desiredSort
datPrimaryRS.Refresh

this will achieve your desired results




Dear 'Key Wiz'

ref my question 21 mar 2007 post = 210725 - Along time ago!

Many thanks for your reply.

I was too impatient and did not give time for replies. I then went down a different route.

Yours Don K O'tay

Was This Post Helpful? 0

Page 1 of 1