SelectionChanged problem

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

cmbBrand.SelectedIndex=-1
cmbModel.SelectedIndex=-1

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
cmbModel.Clear
For k=0 To tblModel.RowCount-1
cmbModel.Add(tblModel.Cell("MODEL_NAME",k))
Next k
tblModel.Filter("")
End Sub

SurrLastItem returns a string enclosed between singles quotes.

Is anyone here that could give me please any help?

Many thanks
Mimmo
 

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
Mimmo
 

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
Mimmo
 
Top