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.
Datagrid sort columns by user
Page 1 of 14 Replies - 41170 Views - Last Post: 12 April 2010 - 11:16 AM
Replies To: Datagrid sort columns by user
#2
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
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
#3
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:
Some of the variables are Form-level, and you will want to populate them.
Charles
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
#4
Re: Datagrid sort columns by user
Posted 04 January 2010 - 05:43 AM
KeyWiz, 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
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
#5 Guest_Tim*
Re: Datagrid sort columns by user
Posted 12 April 2010 - 11:16 AM
Don K O, on 04 January 2010 - 04:43 AM, said:
KeyWiz, 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
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
Page 1 of 1