hi,

i have two listboxes namely list1(contains countries) AND list2(contains places).. the flow is when i select a country in list1, the places will be displayed in list2.
how do I add places into a selected country in list1? also how do i display the places in list2? im new in vb..
i need your help.. plz,any idea from u guysz will help.. thanks!

Recommended Answers

All 5 Replies

I don't have VB open and in front of me at the moment, but basic'ly if you look in your object katalog under listbox you will find what you need.

the basic syntax was

Listbox.add ("text",index) whereby index was not mandatory.
also very important is Listbox.clear() before updating your next list, remove the last one.

you might also take some time and look into containers. depending on where your data comes from and so on, you can setup a container and then during your programm you don't have constantly add each line but just SET your listbox(s) to the appropriat var in your container

To add items to a listbox use the .AddItem method. Now from the sounds of this you will also need to use the .Clear method on List2 before you populate it with places.

Now, how are you going to hold all of this information? Text File, database, code, ini file, other?

Once we know that, then we will be able to help you with the logic of the code and other things you may need.

Good Luck

i would like to store the places that will be entered in an array..

thanks to you guyszz.. got an idea..

Okay, you will need two arrays then. First array will mirror exactly what is in List1...

List1.AddItem "Place1"
Array1(0) = "Place1"
List1.AddItem "Place2"
Array1(1) = "Place2"

Second array will be a two dimensional array.

Dim Array2(0 To NumberOfCountries, 0 To MaxNumberOfPlaces) As String

So in list1 click event you could use a for loop to populate list2.

Dim I as Integer
For I = 0 To MaxNumberOfPlaces
  If Trim(Array2(List1.ListIndex, I)) <> "" Then
    List2.AddItem Array2(List1.ListIndex, I)
  End If
Next I

Good Luck

sorry for not coming back here too soon.. been busy for exams.. thanks for the answers.. it really helped.. thanks again! GBU

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.