Results 1 to 10 of 10

Thread: MSHFLEXGIRD Sort

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    277

    MSHFLEXGIRD Sort

    hihi..

    i have this exmaple code coded on this forum , and it work very well for flexgrid. but when i start to used it on MSHFLEXGRID it become malfunction. What is the problem on this code. when i click on the header, everthing started to sort. it turn out very messy. When i set the properties header, i was thrown with error for the "out of range" msg. Sorry for the lengthly code.

    VB Code:
    1. Private Sub Form_Load()
    2.  With presentation_search.presentationCollection_grid
    3.     .TextMatrix(0, 1) = "Presentation ID"
    4.     .TextMatrix(0, 2) = "Presentation Name"
    5.     .TextMatrix(0, 3) = "Presentation Type"
    6. end with
    7. end sub
    8.  
    9. Private Sub presentationCollection_grid_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    10.  
    11.   ' If this is not row 0, do nothing.
    12.     If presentationCollection_grid.MouseRow <> 0 Then
    13.     Exit Sub
    14.     End If
    15.     ' Sort by the clicked column.
    16.     SortByColumn presentationCollection_grid.MouseCol
    17. End Sub
    18. ' Sort by the indicated column.
    19. Private Sub SortByColumn(ByVal sort_column As Integer)
    20.     presentationCollection_grid.Visible = False
    21.     presentationCollection_grid.Refresh
    22.     ' Sort using the clicked column.
    23.     presentationCollection_grid.Col = sort_column
    24.     presentationCollection_grid.ColSel = sort_column
    25.     presentationCollection_grid.Row = 0
    26.     presentationCollection_grid.RowSel = 0
    27.     ' If this is a new sort column, sort ascending.
    28.     ' Otherwise switch which sort order we use.
    29.     If m_SortColumn <> sort_column Then
    30.         m_SortOrder = flexSortGenericAscending
    31.     ElseIf m_SortOrder = flexSortGenericAscending Then
    32.         m_SortOrder = flexSortGenericDescending
    33.     Else
    34.         m_SortOrder = flexSortGenericAscending
    35.     End If
    36.     presentationCollection_grid.Sort = m_SortOrder
    37.     ' Restore the previous sort column's name.
    38.     If m_SortColumn >= 0 Then
    39.         presentationCollection_grid.TextMatrix(0, m_SortColumn) = Mid$(presentationCollection_grid.TextMatrix(0, m_SortColumn), 3)
    40.     End If
    41.     ' Display the new sort column's name.
    42.     m_SortColumn = sort_column
    43.     If m_SortOrder = flexSortGenericAscending Then
    44.         presentationCollection_grid.TextMatrix(0, m_SortColumn) = "> " & presentationCollection_grid.TextMatrix(0, m_SortColumn)
    45.     Else
    46.         presentationCollection_grid.TextMatrix(0, m_SortColumn) = "< " & presentationCollection_grid.TextMatrix(0, m_SortColumn)
    47.     End If
    48.  
    49.     Debug.Print sort_column; presentationCollection_grid.Col; m_SortColumn '@
    50.     ' Display the FlexGrid.
    51.     presentationCollection_grid.Visible = True
    52. End Sub

    ???
    ocw

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: MSHFLEXGIRD Sort

    The code works fine for both grids.

    When i set the properties header, i was thrown with error for the "out of range" msg.
    Can you explain this? What is properties header?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    277

    Re: MSHFLEXGIRD Sort

    Quote Originally Posted by brucevde
    The code works fine for both grids.

    Can you explain this? What is properties header?
    i only check the ColumnHeader at the properties checkbox. when i click on the row index 0, the grid began to sort but in a messy manner. it amy not be in the same row. it seem that i need to set the header or to do a fix row. but how to set the header? or how should i edit the code to make it function:?

    ???
    ocw

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MSHFLEXGIRD Sort

    Will you try this?

    VB Code:
    1. Private Sub MSHFlexGrid1_DblClick()
    2. '-------------------------------------------------------------------------------------------
    3. ' code in grid's DblClick event enables column sorting
    4. '-------------------------------------------------------------------------------------------
    5.  
    6.     Dim i As Integer
    7.  
    8.     ' sort only when a fixed row is clicked
    9.     If MSHFlexGrid1.MouseRow >= MSHFlexGrid1.FixedRows Then Exit Sub
    10.  
    11.     i = m_iSortCol                  ' save old column
    12.     m_iSortCol = MSHFlexGrid1.Col   ' set new column
    13.  
    14.     ' increment sort type
    15.     If i <> m_iSortCol Then
    16.         ' if clicking on a new column, start with ascending sort
    17.         m_iSortType = 1
    18.     Else
    19.         ' if clicking on the same column, toggle between ascending and descending sort
    20.         m_iSortType = m_iSortType + 1
    21.     If m_iSortType = 3 Then m_iSortType = 1
    22.     End If
    23.  
    24.     DoColumnSort
    25.  
    26. End Sub
    27.  
    28. Sub DoColumnSort()
    29. '-------------------------------------------------------------------------------------------
    30. ' does Exchange-type sort on column m_iSortCol
    31. '-------------------------------------------------------------------------------------------
    32.  
    33.     With MSHFlexGrid1
    34.         .Redraw = False
    35.         .Row = 1
    36.         .RowSel = .Rows - 1
    37.         .Col = m_iSortCol
    38.         .Sort = m_iSortType
    39.         .Redraw = True
    40.     End With
    41.  
    42. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: MSHFLEXGIRD Sort

    hi,
    i want to sort the same values in a flexgrid... how do i do that?(e.g sort by:company)

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: MSHFLEXGIRD Sort

    Use the code above, but change the gridname MSHFlexGrid1 to your Flexgrids name. If you only want to sort on one column, you will have to set the mousecol in the click event, instead of allowing any column to be sorted.

    Also, you have to declare the M_ variables. You can use Integer type.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Posts
    277

    Re: MSHFLEXGIRD Sort

    Quote Originally Posted by dglienna
    Use the code above, but change the gridname MSHFlexGrid1 to your Flexgrids name. If you only want to sort on one column, you will have to set the mousecol in the click event, instead of allowing any column to be sorted.

    Also, you have to declare the M_ variables. You can use Integer type.
    hihi,

    how can i fix a row?when i click on the header, it does not do anything.

    i set my header like this-->

    VB Code:
    1. With MSHFlexGrid1.
    2.     .TextMatrix(0, 1) = "Artifact 1"
    3.     .TextMatrix(0, 2) = "Artifact 2"
    4.     .TextMatrix(0, 3) = "Artifact 3"
    5.     .TextMatrix(0, 4) = "Artifact 4"
    6.     .TextMatrix(0, 5) = "Artifact 5"
    7.     .TextMatrix(0, 6) = "Artifact 6"
    8.     End With

    am i on the right track? i did not set anyproperties to the gird. i use the defult setting of MSHFLEXGRID.
    Last edited by ocw; Dec 20th, 2005 at 10:36 PM.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: MSHFLEXGIRD Sort

    Here's my work in progress of the new sort option:
    Attached Files Attached Files

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: MSHFLEXGIRD Sort

    Quote Originally Posted by ocw
    hihi,

    how can i fix a row?when i click on the header, it does not do anything.

    i set my header like this-->

    VB Code:
    1. With MSHFlexGrid1.
    2.     .TextMatrix(0, 1) = "Artifact 1"
    3.     .TextMatrix(0, 2) = "Artifact 2"
    4.     .TextMatrix(0, 3) = "Artifact 3"
    5.     .TextMatrix(0, 4) = "Artifact 4"
    6.     .TextMatrix(0, 5) = "Artifact 5"
    7.     .TextMatrix(0, 6) = "Artifact 6"
    8.     End With

    am i on the right track? i did not set anyproperties to the gird. i use the defult setting of MSHFLEXGRID.
    Have you tried the code in post #4?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: MSHFLEXGIRD Sort

    I've incorporated it into post #8.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width