Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort MSFlexGrid 1

Status
Not open for further replies.

TimmyNF

Programmer
Aug 26, 2002
11
US
Hi,

I have flexgrid where the last row is a total of data in the rows above. Is there any way I can sort all the rows minus the last one?
 
Dim spql As String
Dim ab, cd As Double
spql = "select * from emp"
RS.Source = spql
RS.Open
If RS.RecordCount > 0 Then
For i = 1 To RS.RecordCount
ab = RS.Fields("salary")
cd = RS.Fields("Netsalary")
RS.MoveNext
Next i
End If
RS.close

'here we will get the totals.

Dim strsql As String
strsql = "SELECT * FROM emp"
RS.Source = strsql
RS.Open
With RS
Do While Not .EOF
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 0) = RS.Fields(0)
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 1) = RS.Fields("salary")
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 2) = RS.Fields("netsalary")
MSFlexGrid .Rows = MSFlexGrid.Rows + 1
Loop
End With
'here we will display the total records. And at the end
'this will display the totals.

MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = ab
MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = cd
RS.close
'Try this this will solve your problem. Best of luck,"
Srinivas_pvl@hotmail.com
 
Dim spql As String
Dim ab, cd As Double
spql = "select * from emp"
RS.Source = spql
RS.Open
If RS.RecordCount > 0 Then
For i = 1 To RS.RecordCount
ab = RS.Fields("salary")
cd = RS.Fields("Netsalary")
RS.MoveNext
Next i
End If
RS.close

'here we will get the totals.

Dim strsql As String
strsql = "SELECT * FROM emp order by salary"
'here you can write sorting quarry. Your last record
' will not be effected
RS.Source = strsql
RS.Open
With RS
Do While Not .EOF
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 0) = RS.Fields(0)
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 1) = RS.Fields("salary")
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 2) = RS.Fields("netsalary")
MSFlexGrid .Rows = MSFlexGrid.Rows + 1
Loop
End With
'here we will display the total records. And at the end
'this will display the totals.

MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = ab
MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = cd
RS.close
'Try this this will solve your problem. Best of luck,"
Srinivas_pvl@hotmail.com
 
With a flexgrid named FG1 :


Private Sub FG_Sort(ByVal Col2Sort As Long)
Dim rows As Long
Dim cols As Long
Dim fixcol As Long
Col2Sort = Col2Sort - 1
rows = FG1.rows
cols = FG1.cols
fixrows = FG1.FixedRows
FG1.Col = Col2Sort
FG1.Row = fixrows
FG1.RowSel = rows - fixrows - 1
FG1.ColSel = Col2Sort
FG1.Sort = 1
End Sub


Sort options are :

FlexSortNone = 0
FlexSortGenericAscending = 1
FlexSortGenericDescending = 2
FlexSortNumericAscending = 3
FlexSortNumericDescending = 4
FlexSortNoCaseAscending = 5
FlexSortNoCaseDescending = 6
FlexSortStringAscending = 7
FlexSortStringDescending = 8
FlexSortCustom = 9
 
Merlinx has it.
From the Docs.
"The Sort property always sorts entire rows. To specify the range to be sorted, set the Row and RowSel properties. If Row and RowSel are the same, the MSHFlexGrid will sort all non-fixed rows." Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top