Results 1 to 7 of 7

Thread: Sort a MSHFlexGrid using Row and RowSel

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    73

    Sort a MSHFlexGrid using Row and RowSel

    Scenario:

    I want to sort a mshflexgrid within a specified range of rows, which is everything but the last row. The last row of the grid, I am using for the totals and therefore do not want to sort. I am sorting using the last column which is the total for each row.

    mshflexgrid.row = 1 'Begin Row selection
    mshflexgrid.rowsel = mshflexgrid.rows-2 'End row selection
    mshflexgrid.col = mshflexgrid.cols-1 'selected column
    mshflexgrid.sort = flexSortNumericDescending

    What I am getting:

    The flexgrid gets sorted but the last total row gets sorted as well and because it is the total and has the highest number, it is placed on the top.

    What I am looking for:

    I want not to sort the last row of the flex.

    Thanks in advance,

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    73

    Unhappy

    Anyone!!

  3. #3
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    save the last row values to an array,
    cut the row,
    sort,
    add the row to the end.

    hey, it works.
    Merry Christmas

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    73
    Ok, I will try that. But, I thought the idea behind RowSel is to be able to select a range of rows for sorting and stuff like that. If anyone have used it before then I would like to see a sample code.

    Thank you for the reply

  5. #5
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    I guess you are correct. I didn't know you could sort a range of rows.

    I did this:
    VB Code:
    1. Private Sub Command6_Click()
    2.     xgrid.Row = 2
    3.     xgrid.RowSel = 8
    4.     xgrid.Sort = 2
    5. End Sub

    I had a grid with numbers 1,2,3,4,5..10
    and it reversed them, only within the range.

    double check that:
    -you set the .row AND the .rowsel
    -you set the correct .col
    -remember that rows are numbered 0 to .count-1

    it should work for ya.
    Merry Christmas

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    73
    I thought so. If you look into my original post, I have a sample code of what I tried. I am mainly concern about

    mshflexgrid.rowsel = mshflexgrid.rows-2

    The reason i subtracted two is not to include the last row, which is grid.rows-1. But, no matter what number I put there (I just tried putting 3, 4 and like), it still sorts my last row.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    73
    JPicasso, thanks for replying to my post. I did find the solution using the same code I had before, the only difference is that I changed the position of the statement. I set .Row and .Col before I set .RowSel and it works. I thought, setting .Row after .RowSel would reset .RowSel but apparently .Col also resets .RowSel (Don't understand why though!). Hey, you learned something new and i did too..

    Thanks

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