Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ComboBox.DataSource
Message
De
12/08/2005 19:23:35
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01040543
Message ID:
01040635
Vues:
15
DataSources can be tricky ... If they're already set, and something in that source changes (like when you added to the collection), it's not recognized as being there. Simply re-setting the DataSource to your collection doesn't do the trick (since, I'm guessing, it was already set to that DataSource so it probably doesn't "re-assign" it) ... hence the need to set it to null first and then re-assign it. It makes sense, somewhat, if you think about it in these terms.

~~Bonnie


>Bonnie,
>Yes the DataSource is set to this.oXPortCollection before the code that I posted was executed.
>There were items in the collection (and in the combobox) before the code below was executed.
>
>The reason I set it to null first was because I remembered having to do something like that in VFP.
>Einar
>
>>Just a guess, Einar ... but did you already have the DataSource set, then added a new item to the collection?
>>
>>~~Bonnie
>>
>>
>>
>>>I found this a little odd this morning. Considder the code below:
>>>
>>>
>>>this.oXPortCollection.Add(oXPrt);
>>>
>>>// Without the line below the new item added above does not show up in the combobox
>>>this.cboSboxes.DataSource = null;
>>>
>>>this.cboSboxes.DataSource = this.oXPortCollection;
>>>
>>>
>>>At first I did not have the line setting the DataSource to null but without that line the combobox did not display the newly added item to the collection. I added the collection to the watch window and could see that the new item was in there. I also wrote to the console all the items in the collection.
>>>
>>>Why do I have to set the DataSource to null first?
>>>
>>>I also experimented with code where I created a new collection, added the new item then looped through the old collection and added all the items from the old collection to the new collection. Then I set the old collection to equal the new collection and set the combobox' datasource to the old collection, in that case I did not have to set the datasource to null first.
>>>
>>>Any thoughts.
>>>
>>>Thanks,
>>>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform