table: SelectionChanged() and SelectedRow

Discussion in 'Questions (Windows Mobile)' started by stbi, Jun 28, 2007.

  1. stbi

    stbi Member Licensed User

    I have a form with an empty table. Then I populate the table with a few data rows from a CSV file. No table cell is selected after filling the table.
    When I now call table1.SelectedRow the result is 0 :confused: ... so I don't know wether no cell was selected so far or wether the first row was really selected.
    But I am a clever one :sign0137: ... I defined a global var named actualRow and an SelectionChanged-event:
    So I'm able to check an explicit cell selection .

    This works only for the first time. After the cell selection is handled by the program I can reset actualRow to -1 but I can't deselect the cell.
    And if the user taps on the table header or elsewhere outside the table and deselects the cell, I have no event to get noticed about deselection.

    It would be useful if SelectedRow and SelectedCol would return -1 if no cell is actually selected.

    Edit: table1.Refresh or table1.SelectCell("col1", -1) don't deselect.
    Last edited: Jun 28, 2007
  2. dzt

    dzt Active Member Licensed User

    I think that you have no chance to remove the selection this way. Try to remove selected row and add it again.
    Didn't testit.
  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I think but am not sure that all is needed is to move the focus onto a different control.
    You could possibly try moving the focus onto the Form.

    Please let me know if this works.

  4. stbi

    stbi Member Licensed User

    Moving the focus to another control works, but moving the focus to the form doesn't work. The control must be visible, if you want an unvisible control you can use a button with size 0,0. One disadvantage remains: if the user selects the same row and taps the same cell, the SelectionChanged-event is not fired (because really nothing changed).

    I found another solution: SelectCell() to an invisible (colwidth=0) cell in the first row. So every tap on a cell fires the SelectionChanged-event.

    But thank you RandomCoder, your tip led me back on track :)

    @dzt: thank you, too! I didn't test your solution because I had a bad feeling about deleting master data. And I presume that cell slection will remain active.
  5. dzt

    dzt Active Member Licensed User

    Well I think that,

    moving the focus to another control even with width and height=0 doesn't remove the selection from table control (just removes the focus)

    making a length=0 cell prevents it from beeing selected by the stylus, but doesn't prevents it from beeing selected by the arrow keys.

    Not very sure for the above

  6. willisgt

    willisgt Active Member Licensed User

    stbi, I'm having a small problem with this solution.

    I create a table, create the columns, and assign the cell values one row at a time. Finally, I try a SelectCell(), and get the error:

    'CurrentCell could not be set at this time. Moving your code to the Form.Load event should solve this problem.'

    Any ideas?

  7. specci48

    specci48 Well-Known Member Licensed User

    Hello willisgt,

    I think you are trying to select the tablecell within an event sub. There are some commands (i don't know them all) you cannot execute within such an event sub. :sign0161:
    Look at this thread and try to use a timer to solve your problem.

  8. alfcen

    alfcen Well-Known Member Licensed User

    Hi willisgt

    I eliminate this error message by using SelectCell after Form.Show (the form that contains the table). Example:

    Sub mnuSetting_Click
    If tblCity.RowCount < 1 Then
    0))=tblCity.Width / 2 - 10
    1))=tblCity.Width / 2 - 10
    End If
    End Sub
  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