Area Selection by combo boxes

mozaharul

Active Member
Licensed User
Hi all,

We want to select sepecif districts and sub districts as well under a selected division from the combo boxes used. And want to clear the value of district and sub district when there is a change in the division selection.

The code works but with a error message.

Please have a look and help.

regards,
 

Attachments

  • area Selection.sbp
    6.1 KB · Views: 267

Rioven

Active Member
Licensed User
Longtime User
The SelectedIndex=-1 that triggers errors.
You may consider assigning these combobox at index 0 to be "" blank or "-none-" then you can use or initialized selectedIndex=0.
 

mozaharul

Active Member
Licensed User
Hi,

The same code (cmbthana.selectedindex=-1) works for the sub districts(cmbthana combo box) without any error message, then wonder what is the cause for not working with the districts (cmbzilla combo box).


regards,
 

klaus

Expert
Licensed User
Longtime User
Hi,
ComboBox1.SelectedIndex=-1 does not mean clear the selected text.
You must clear the text of the selected item first.

As soon as you have filled a ComboBox and selected an item then ComboBox1.SelectedIndex=-1 gives an error.

ComboBox1.Clear does not clear the displayed text.
Because, generally, a default selection is made.

But why, after having initialized a combobox, not preselect the first item with ComboBox1.SelectedIndex=0 as the default, so the user has already one, and it avoids also your problem in a different way.

I have joined a modified code that solves your problem, and shows better the solution than the text.

For comparison, to show another way, I have replaced the
If Then
Else If
End If etc

by
Select
Case 0
Case 1
.
.
End Select

Best regards
 

Attachments

  • area Selection_1.sbp
    7.5 KB · Views: 273
Top