I want to add all of the items from a listbox inside of a list. This list is a string-list and a part of the private members from my object "Deur".
When i try to loop over the listbox listitems and add them inside this list, i get an error saying "System.NullReferenceException: 'Object reference not set to an instance of an object.'"
I've tried to Convert the "Listbox.Text" item to a string (which it alredy is), but that didn't help.
Here is the code where i try to add it to my list: LBSupplementen is the ListBox, b.SupplementenLijst is the List.
if (LBSupplementen.Items.Count > 0)
foreach (ListItem i in LBSupplementen.Items)
b.SupplementLijst.Add(Convert.ToString(i.Text));
and here is where i define my List in my object class "Deur":
private List<string> _SupplementLijst;
public Deur()
{
_GaasID = GaasID;
_Gaas = Gaas;
_ProductID = ProductID;
_Product = Product;
_Hoogte = Hoogte;
_Breedte = Breedte;
_KleurID = KLeurID;
_Kleur = Kleur;
_SupplementLijst = SupplementLijst;
_SupplementLijstID = SupplementLijstID;
_Prijs = Prijs;
}
public List<string> SupplementLijst
{
get { return _SupplementLijst; }
set { _SupplementLijst = value; }
}