Keep selected row with TableSort

Discussion in 'Questions (Windows Mobile)' started by RB Smissaert, Jan 6, 2009.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Is it possible to do a table sort and keep the currently selected row selected?
    I know I could do that by putting the cells of that row in a variable and then after the sort loop through the table, find that row and select it, but that would be too slow.

    RBS
     
  2. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Actually performance is not bad when I do code like this:

    Before the sort:

    Sub MarkPreSortRow(lRow)

    Table1.AddCol(cNumber, "MarkPreSortRow", 0, False)
    Table1.Cell("MarkPreSortRow", lRow) = 1

    End Sub


    And after the sort:

    Sub SelectPreSortTableRow(strColumnName)

    Dim i

    For i = 0 To Table1.RowCount - 1
    If Table1.Cell("MarkPreSortRow", i) = 1 Then
    Table1.RemoveCol("MarkPreSortRow")
    Table1.SelectCell(strColumnName, i)
    Return
    End If
    Next i

    End Sub


    And I take it there is nothing better than this.


    RBS
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    If your table includes a unique key you can just save this key and search for it after resorting.
    It is almost always a good idea to have a unique key for each row.
     
  4. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Good point. Some of the tables indeed have a unique key and in that case I could maybe save a bit of time by not adding the extra column.
    To add the unique key if I don't otherwise need it won't probably be worth it.

    RBS
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice