stnkyminky
Programmer
First off let me say that anyone who helps explain why this is happening will receive a star.
I've got several classes(Publication and Ad). The publication class contains information about a trade magazine(name, issue date). The Ad class contains information about an Ad that is in a magazine(name, products mentioned, etc)
I have a public property in the Publication class that is an Ad Collection (Ads). When I populate the publication class, I also load all of the ads in that issue. I have a function that returns an Ad Collection (Ads) and it is assigned in a For Loop ----->
I then take the Publication Collection (Publications) and add the objects to a combo box via For Each loop
Within the GetPublications function was a call to a separate sub that would add the Ads to the Publication Object
Now, when the user clicks on a publication (SelectedIndexChange Event), I take the SelectedItem in the combo box and iterate through the Ads and add them to a separate combo box
The code above existed in Try..Catch. In the Finally statement I would do the following
Clicking through each item in the publication combo box worked great and returned the ads in that publication. After reaching the last item, I then tried to access the first item in the publication combo. At that point the Ads collection in the Publication object was Nothing. I wasn't altering the code anywhere in the form.
Just as a stab to fix the problem. I removed code that would "Clear" the collection (code above). After commenting out that code, the ads are retained. My questions is this.
Scott
Programmer Analyst
<{{><
I've got several classes(Publication and Ad). The publication class contains information about a trade magazine(name, issue date). The Ad class contains information about an Ad that is in a magazine(name, products mentioned, etc)
I have a public property in the Publication class that is an Ad Collection (Ads). When I populate the publication class, I also load all of the ads in that issue. I have a function that returns an Ad Collection (Ads) and it is assigned in a For Loop ----->
Code:
pub(i).Ads = GetAds(pub(i).ID)
I then take the Publication Collection (Publications) and add the objects to a combo box via For Each loop
Code:
dim pub as Publication
dim pubs as Publications
pubs = GetPublications()
for each pub in pubs
ComboBox1.Items.Add(pub)
Within the GetPublications function was a call to a separate sub that would add the Ads to the Publication Object
Code:
count = col.Count - 1
For i = 0 To count
col(i).Ads = obj.getAds(col(i).ID)
Next
Now, when the user clicks on a publication (SelectedIndexChange Event), I take the SelectedItem in the combo box and iterate through the Ads and add them to a separate combo box
Code:
cboItem.Items.Clear()
_ads = CType(cboPub.SelectedItem, LeadSystem.BAL.Publication).Ads
If _ads.Count > 0 Then
For i = 0 To count
cboItem.Items.Add(_ads(i))
Next
Else
cboItem.Enabled = False
cboItem.Items.Add("No Ads Available")
End If
cboItem.SelectedIndex = 0
The code above existed in Try..Catch. In the Finally statement I would do the following
Code:
_ads.clear()
_ads = Nothing
Clicking through each item in the publication combo box worked great and returned the ads in that publication. After reaching the last item, I then tried to access the first item in the publication combo. At that point the Ads collection in the Publication object was Nothing. I wasn't altering the code anywhere in the form.
Just as a stab to fix the problem. I removed code that would "Clear" the collection (code above). After commenting out that code, the ads are retained. My questions is this.
Scott
Programmer Analyst
<{{><