So I am programming some kind of a member data-storage application and I'm getting a NullReferenceException when I try to create a new form instance.
Code in the main:
List<Object> list_objects = objects.get_Objects();
try
{
New_Object obj = new New_Object(this, objects, list_objects.ElementAt(lv_data.FocusedItem.Index));
obj.Show();
}catch(NullReferenceException)
{
MessageBox.Show("No object selected.");
}
Code in "New_Object"
public New_Object(Main main, Objects objects, Object obj)
{
btn_create.Text = "Cahnge";
btn_create.Click += btn_change_Click;
this.obj = obj;
}
There is an existing object in list_objects with the index of 0 and the lv_data.FocusedItem.Index is also 0, so why is this not working?
Thanks for helping and explaining