Delete all rows on a PopUpMenu

Hi all!

I have 2 PopUpMenus.
The first one called “State” Has all States of the country, for Example: Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Texas, etc.

And the second one called “County”.
And when I Select x State on PopupState, prints all the counties on popupCounty.
Example If I Choose “Alaska”, must print on popupCounty:
Anchorage,Fairbanks,Juneau,Badger,Knik-Fairview,College,Sitka, etc etc.

I’m Using a Select Case in order to evaluate popEstado.text on “Change Event”
And AddRow for each County on popUpCounty

I suppose to use a Case Else to DeleteAllRows existent and add the pertinent rows for the state on question.

I tried to use a “for” like this:
For i As Integer = 1 to popCounty.ListCount

But It doesn’t Work.

What Am I doing wrong? Any Suggestions?


Axel is correct. When you select the state from popState, then

  1. Get a record set of all counties that are in the state from popState
  2. popCounty.DeleteAllRows
  3. Loop and add counties for the relevant state.

And, to explain why your example wasn’t working, when deleting items, you should work top down. If there are 6 items in your list, as you delete each item, you will reach a point where there are less rows than your value of ‘i’. (Also, rows are 0-based)

For i As Integer = popCounty.ListCount - 1 DownTo 0