[b][red]This message was edited by EasyWAy at 2005-1-12 3:38:24[/red][/b][hr]
Hi I am having problem with the sorting of records in an MSHflegrid. I am trying to do a numeric ascending order sort on my column 15 to 17 and then a descending order sort on the column 18. All of these columns have numeric data, except for column 18, which can also have NULL value. So, I perform a descending sort on the column 18 first.
MSHFlexgrid1.column = 18
MSHFlexgrid1.colsel = 18
MSHFlexgrid1.sort = 4 ' numeric descending sort
The above liens work, because I have tried it without doing the next step and it was sorting on descending order.
Then I perform an ascending sort on the columns 15 to 17 (which means, column 15,within which column 16 within which column 17 are sorted on numeric ascending order)
MSHFlexgrid1.column = 17
MSHFlexgrid1.colsel = 15
MSHFlexgrid1.sort = 3 ' numeric ascending sort
But, what happens is that when I perform the numeric ascending sort on the column 15 through 17, it also sorts the column 18 on the ascending order (It shouldn't. But, it does). This, effectively, means I am not able to sort the column 18 in descending order, unless that is the only column to be sorted. I don't know where I am going wrong. Can someone help me?
Comments
: Hi I am having problem with the sorting of records in an MSHflegrid. I am trying to do a numeric ascending order sort on my column 15 to 17 and then a descending order sort on the column 18. All of these columns have numeric data, except for column 18, which can also have NULL value. So, I perform a descending sort on the column 18 first.
: MSHFlexgrid1.column = 18
: MSHFlexgrid1.colsel = 18
: MSHFlexgrid1.sort = 4 ' numeric descending sort
: The above liens work, because I have tried it without doing the next step and it was sorting on descending order.
:
: Then I perform an ascending sort on the columns 15 to 17 (which means, column 15,within which column 16 within which column 17 are sorted on numeric ascending order)
: MSHFlexgrid1.column = 17
: MSHFlexgrid1.colsel = 15
: MSHFlexgrid1.sort = 3 ' numeric ascending sort
:
: But, what happens is that when I perform the numeric ascending sort on the column 15 through 17, it also sorts the column 18 on the ascending order (It shouldn't. But, it does). This, effectively, means I am not able to sort the column 18 in descending order, unless that is the only column to be sorted. I don't know where I am going wrong. Can someone help me?
Simple answer seems to be that the grid can only do one sort at a time. If you are looking to sort on multiple criteria you'll probably have to do it in the database or the underlying recordset.
[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
[code]
$ select * from users where clue > 0
no rows returned
[/code]
: : Hi I am having problem with the sorting of records in an MSHflegrid. I am trying to do a numeric ascending order sort on my column 15 to 17 and then a descending order sort on the column 18. All of these columns have numeric data, except for column 18, which can also have NULL value. So, I perform a descending sort on the column 18 first.
: : MSHFlexgrid1.column = 18
: : MSHFlexgrid1.colsel = 18
: : MSHFlexgrid1.sort = 4 ' numeric descending sort
: : The above liens work, because I have tried it without doing the next step and it was sorting on descending order.
: :
: : Then I perform an ascending sort on the columns 15 to 17 (which means, column 15,within which column 16 within which column 17 are sorted on numeric ascending order)
: : MSHFlexgrid1.column = 17
: : MSHFlexgrid1.colsel = 15
: : MSHFlexgrid1.sort = 3 ' numeric ascending sort
: :
: : But, what happens is that when I perform the numeric ascending sort on the column 15 through 17, it also sorts the column 18 on the ascending order (It shouldn't. But, it does). This, effectively, means I am not able to sort the column 18 in descending order, unless that is the only column to be sorted. I don't know where I am going wrong. Can someone help me?
:
: Simple answer seems to be that the grid can only do one sort at a time. If you are looking to sort on multiple criteria you'll probably have to do it in the database or the underlying recordset.
:
:
: [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
:
: [code]
: $ select * from users where clue > 0
: no rows returned
: [/code]
:
: The Excell worksheet lets me do it and as I understand, Excel uses VB behind it. What worries me is, in the sort property of the Flexgrid, it says that we have to mention the columns to be sorted, using the 'col' and 'Colsel' properties. So, one would expect that it is only going to sort those columns which we specified in those lines (namely, column 15 through 17 in my example). If this is going to sort column 18 as well, what's the point in mentioning the sorting column range? Do you know if there is anyway I can specify the sort to ignore some columns when performing a sort? If I sort the database using the SQL, it is taking too long and therefore, it is not practical. Eitherway, I really appreciate your quick response to my query. Thank you very much.
Excel does have VB inside it, for some definition of the word "inside", but Excel is not using heirarchical flexgrid controls so that point is moot. A quick scan of the documentation on the .Sort property indicates that setting .Col to 15 and .ColSel to 17, and then setting .Sort to (for example) flexSortGenericAscending will have the same effect, more or less, as "order by 15 asc, 16 asc, 17 asc" in the database. My guess is that it isn't really sorting column 18 as well, you just think it is because it's not behaving as you expect it to. If you're trying to do something like "order by 18 desc, 15 asc, 16 asc, 17 asc" and you can't or won't use the database query or the ADO recordset object's .Sort property, then it seems you'll have to set the grid's .Sort = flexSortCustom and use the Compare event to tell the grid how two records compare. Good luck. Here is the documentation on the Compare event:
Occurs when the Sort property for the MSHFlexGrid is set to Custom Sort (9), so the user can customize the sort process.
Syntax
Private Sub object_Compare(row1, row2, cmp)
The Compare event syntax has these parts:
Part Description
object An object expression that evaluates to an object in the Applies To list.
row1 A Long integer that specifies the first row in a pair of rows being compared.
row2 A Long integer that specifies the second row in a pair of rows being compared.
cmp An integer that represents the sort order of each pair, as described in Settings.
Settings
The event handler must compare row1 and row2 and set cmp to:
Setting Description
1 If row1 should appear before row2.
0 If both rows are equal or either row can appear before the other.
1 If row1 should appear after row2.
Remarks
When the Sort property is set to 9 (Custom Sort), the Compare event occurs once for each pair of rows in the MSHFlexGrid. As the Compare event uses row numbers instead of text values, you can compare any property value for that row, including RowData.
Note While custom sorts are slower than built-in sorts, they provide the flexibility to sort a row by any column or using any cell property.
[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
[code]
$ select * from users where clue > 0
no rows returned
[/code]
[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
[code]
$ select * from users where clue > 0
no rows returned
[/code]