0

hope you all doing great, so the problem occurs when I call a static method on a different form, this is the method I'm calling

public static void UpdateUI(int _index)
        {
            PictureBox_VehiclePicture.Image = VehicleList[_index].Image;
            Label_VehicleName.Text = VehicleList[_index].Modelname;
            Label_VehicleID_Info.Text = VehicleList[_index].Modelid.ToString();
            Label_VehicleType_Info.Text = VehicleList[_index].Type;
            Label_VehicleClass_Info.Text = VehicleList[_index].Class;
            Label_VehicleAnim_Info.Text = VehicleList[_index].Anim;
            ListBox_VehicleList.SelectedIndex = _index;
        }

This is where I call it

 private void Button_VehicleID_Click(object sender, EventArgs e)
        {
            this.Close();
            Form_Vehicle._index = int.Parse(NumericUpDown_VehicleID.Value.ToString());
            Form_Vehicle.UpdateUI(Form_Vehicle._index);
        }

These are the errors

**PictureBox_VehiclePicture**.Image = VehicleList[_index].Image;
                **Label_VehicleName**.Text = VehicleList[_index].Modelname;
                **Label_VehicleID_Info**.Text = VehicleList[_index].Modelid.ToString();
                **Label_VehicleType_Info**.Text = VehicleList[_index].Type;
                **Label_VehicleClass_Info**.Text = VehicleList[_index].Class;
                **Label_VehicleAnim_Info**.Text = VehicleList[_index].Anim;
                **ListBox_VehicleList**.SelectedIndex = _index;
Oussama Essamadi
  • 358
  • 8
  • 15
  • Why would a static method know about your instance variables? – maccettura Jul 26 '17 at 18:06
  • There is the main form which contains vehicles information where a button called 'search' is located, when the search button is pressed, an other form is opened which provides options for searching – Oussama Essamadi Jul 26 '17 at 18:07
  • 3
    You can't access no-static members from a static method. Non-static members are *instance* members and require an instance in order to be used. – David Jul 26 '17 at 18:10
  • Read more on [static methods](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members) – Guillaume CR Jul 26 '17 at 20:32

0 Answers0