1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

SelectionChanged problem

Discussion in 'Questions (Windows Mobile)' started by skipper, Apr 9, 2008.

  1. skipper

    skipper Member Licensed User

    I noticed a strange behaviour on combobox related to the SelectionChanged event. I'll try to explain what happens. I have 2 comboboxes: the first one (cmbBrand) is filled with BRAND values from a single column table, the second combobox (cmbModel) is filled with MODELS values form a two columns (BRAND, MODELS) table. At runtime, before entering the input routine, I call the Cleanup routine containing the following instructions


    During input, the program fires a cmbBrand_SelectionChanged (Index, Value) event that filters the two colum table based on the selected BRAND, and then cleanups and reloads the cmbModel in order to show only the Models of the selected Brand.

    After input, the data are saved to a SQL table and then the program calls again the above Cleanup routine.

    At that point the program raises an "Object reference not set to an instance of an object" and points to the cmbBrand.SelectedIndex=-1 instruction.

    Commenting out the entire SelectionChanged routine, the Cleanup routine is called again and again without errors.

    Here is the routine

    Sub cmbBrand_SelectionChanged (Index, Value)
    tblModel.Filter("MODEL_BRAND = " & SurrLastItem(Value))
    cmbModel.SelectedIndex = -1
    For k=0 To tblModel.RowCount-1
    Next k
    End Sub

    SurrLastItem returns a string enclosed between singles quotes.

    Is anyone here that could give me please any help?

    Many thanks
  2. Erel

    Erel Administrator Staff Member Licensed User

    Where is the "cmbBrand.SelectedIndex = -1" line?
  3. skipper

    skipper Member Licensed User

    Hello Erel,
    both the instructions are in the CleanFields routine togheter with other field cleanup instructions

    Sub CleanFields
    txtID.Text = ""
    chkJava14.Checked = False
    cmbModel.SelectedIndex = -1
    cmbBrand.SelectedIndex = -1
    txtMACAddress.Text = ""
    End Sub

    The routine is called 2 times: before accepting the input and after saving the record. In the meantime (during the input), the cmbBrand_SelectionChanged is fired

    Many thanks for your help
  4. Erel

    Erel Administrator Staff Member Licensed User

    There is a problem with setting the index to -1 and catching the SelectionChanged event.
    It will be fixed in the next version.
    You can add a blank value as the first value or you can use cmbBrand.Text = "".
  5. skipper

    skipper Member Licensed User

    Many thanks Erel,

    I fixed it changing only the combo raising the event and it works (on the desktop). I'll try on device.

    Please, feel free to move the thread to the appropriate section.

    Many thanks again
  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