Greg J
2012-07-20T22:43:37Z
I have iGrid 4.70 displaying email information. to sort the Subject column correctly I need to remove the RE, FWD etc prefixes from the subject field. I have achieved this by creating a second column with this data in it which is hidden. In the ColHeaderClick event I detect when the client clicks on the subject column and do the sort on the hidden column instead. This gives the appearance that the Subject column is sorted and has ignored the prefixes.

This works perfectly however I cannot work out how to display the sort direction icon in the Subject column header. Every other column has it displayed except the Subject column.

So, when the Subject column is clicked I need to perform the sort on the hidden column (done) AND then show the appropriate sort icon in the (unsorted) Subject column header.

Any help would be greatly appreciated.

thanks in advance

Greg J
Igor/10Tec
2012-07-23T09:00:52Z
Sure, if you ignore the default sorting in the ColHeaderClick event, the sort icon isn't displayed as ALL sort actions are abandoned - that's why this is not a bug.

To do what you need, use the ColSortKey property. It indicates whether a column is sorted or not, and it's order if several columns are sorted. Set it to zero for all columns except your special column; for this column, set it to 1.
Greg J
2012-07-26T18:16:03Z
Hi Igor,

Thanks for your prompt response although I am having difficulty getting your proposed solution to work. I re-read my question and it probably didnt explain what I want to do very well so I want to try to explain it better.

So, when a user clicks a column, it is sorted in ascending order and a triange appears in the column header indicating that this is the column that the data is sorted by and which direction the data is sorted in. If they click the same header again, the direction toggles and the icon changes accordingly.

EXCEPT, when 'Subject' column 7 is clicked, we actually want to sort the grid by column 8 (hidden from view) BUT still want to display the direction icon in column 7 even though it is sorted by column 8.

I am only allowing the user to sort by one column at a time.

Here is the code that does the sorting correctly however when column 7 is clicked, no direction icon appears in that column (as I would expect it to).

        
    Dim srt As iGrid470_10Tec.SortGroupObject
    Dim lngOrder As Long
    
    Set srt = grdMsg.SortObject
    bDoDefault = False
    
    If grdMsg.RowCount = 0 Then GoTo ExitPoint
        
    'col 7: Subject (visible)  << when this is clicked...
    'col 8: conversation (hidden) << sort by this field BUT show the sort icon in col 7
    
    If srt.SortCol(1) = lCol Or srt.SortCol(1) = 8 And lCol = 7 Then
        If srt.SortOrder(1) = igSortAsc Then
            lngOrder = igSortDesc
        Else
            lngOrder = igSortAsc
        End If
    End If
    
    If lCol = 7 Then
        grdMsg.DoDefaultSort lCol + 1, Shift, lngOrder
    Else
        grdMsg.DoDefaultSort lCol, Shift, lngOrder
    End If

So with this code if I select a column other than 7, it sorts by that column and shows the triangle icon that indicates the direction of the sort. If I click the same column again, it toggles the direction and the icon. Great!

If I click 'Subject' (column 7), the grid is sorted by the hidden column 8 (great) but no direction icon appears in the 'Subject' column heading.

So in this case I want to FORCE the triangle sort icon appear in column 7 even though it is sorted (correctly) by column 8.

Hope that makes sense.

Regards

Greg J
Igor/10Tec
2012-07-27T07:33:54Z
Greg, Have you noticed my note regarding the ColSortKey property in post #2? You need to ADD this loop to your code, and all will work as expected.
Greg J
2012-08-03T21:31:01Z
Hi Igor,

Thanks for spelling that out for me, I had that loop INSTEAD of the column sorting code rather that in ADDITION. It now works as expected however the direction of the arrow does not change when the sort order is reversed. Is there any way to toggle the arrow to correspond with the direction of the sort?

For those that may be interested, the following code successfully displays the icon in the non sorted column.


    If lCol = 7 Then
        grdMsg.DoDefaultSort lCol + 1, Shift, lngOrder
        For i = 1 To grdMsg.ColCount
            If Not i = 7 Then grdMsg.ColSortKey(i) = 0
        Next
        grdMsg.ColSortKey(7) = 1
    Else
        grdMsg.DoDefaultSort lCol, Shift, lngOrder
    End If

But as stated at the moment the icon does not change when the order changes.

Cheers

Greg J
Greg J
2012-08-03T21:47:45Z
all good!

I worked it out. The following code works as expected.


If lCol = 7 Then
    grdMsg.DoDefaultSort lCol + 1, Shift, lngOrder
    For i = 1 To grdMsg.ColCount
        If Not i = 7 Then grdMsg.ColSortKey(i) = 0
    Next
    grdMsg.ColSortKey(7) = 1
    grdmsg.ColSortOrder(7) = lngOrder
Else
    grdMsg.DoDefaultSort lCol, Shift, lngOrder
End If

Thanks again for your great advice and an excellent component.

Cheers

Greg J