-1

Im trying to use the Delete_Click funktion as laid out in https://stackoverflow.com/a/46898543/12955083

private void Delete_Click(object sender, EventArgs e){  
lararLista.Items.Clear(); }

however I get error CS0122 'Collection.Items' is inaccessible due to its protection level

The collection Larare is defined in binding list as lararLista = new BindingList<Larare>();

and the code for Larare is

class Larare : Personal, ILarare
    {
        #region Variabler och ctor

        private string namn;
        private int personalID;
        private long personNummer;
        private long personNnummer;
        private string email;
        private int telNr;
       

        public Larare(string Namn, int PersonalID, long PersonNummer, string Email, int TelNr)
        {
            this.Namn = namn;
            this.PersonalID = personalID;
            this.PersonNummer = personNnummer;
            this.Email = email;
            this.TelNr = telNr;
        }

and the getter and setter are defined in a class that it inherits from

    class Personal : IPersonal
    {
        private string namn;
        private int personalID;

        private long personNnummer;
        private string email;
        private int telNr;


        private string taBort;

        public string Namn
        {
            get { return namn; }
            set { namn = value; }
        }
        public int PersonalID
        {
            get { return personalID; }
            set { personalID = value; }
        }
        public long PersonNummer
        {
            get { return personNnummer; }
            set { personNnummer = value; }
        }
        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        public int TelNr
        {
            get { return telNr; }
            set { telNr = value; }
        }


        public string TaBort
        {
            get { return taBort; }
            set { taBort = value; }
        }

where is the problem?

edit:

 void lararLista_AddingNew(object sender, AddingNewEventArgs e)
    {
        e.NewObject = new Larare(personalNamnText.Text, int.Parse(personalPersonalIDText.Text), long.Parse(personalPersonnummerText.Text),
            personalEmailText.Text, int.Parse(personalTelNrText.Text));

    }

or lararLista.Add(new Larare("Rasmus", "123", "198911224130", "Rasmus@HS.se", "0704554488"));

is the code for adding new objects to the collection

Ramzez
  • 1
  • 4
  • 1
    did you specify an access modifier for your `class`? if not, c# defaults to `internal` - not to `public`. also: nowhere in the code you provided do you do anything with `Collection.Items`...? – Franz Gleichmann Jan 13 '21 at 18:58
  • objects are added with void lararLista_AddingNew(object sender, AddingNewEventArgs e) { e.NewObject = new Larare(personalNamnText.Text, int.Parse(personalPersonalIDText.Text), long.Parse(personalPersonnummerText.Text), personalEmailText.Text, int.Parse(personalTelNrText.Text)); } That is in the same file. I have changed the acess modifiers to public but no change – Ramzez Jan 13 '21 at 19:07
  • plase add that code to your **question** - because in a comment, it is completely unreadable. thus being said: your code snippet still doesn't do anything with `Collection.Items` – Franz Gleichmann Jan 13 '21 at 19:09

1 Answers1

2

The Items property in a BindingList is not public, so you can't access it directly. Try:

lararLista.ClearItems();
Russ
  • 4,091
  • 21
  • 32