Hey there!
I have a class called "student" which consists of a string "surname" and a string array "subjects". I also have a list of type "student" of all the students.
I have a button that adds a given student to the listview and creates a new object in the list. Let's say it works like this:
I'm now trying to add a code that, upon clicking on a contextmenustri p on the listview, would delete the student from BOTH the listview and the students LIST.
However, I can't figure out how to remove THE SAME student from the students LIST. It's because I'd need to know the index of the student I'm selecting on listview, or I'd need to get the value of surname based on the selection. Any ideas how I can pull it out?
I have a class called "student" which consists of a string "surname" and a string array "subjects". I also have a list of type "student" of all the students.
Code:
public class student { public static string surname; public string[] subjects = new string[10]; }; List<student> students = new List<student>();
Code:
private void button1_Click(object sender, EventArgs e) { ListViewItem lvi = new ListViewItem(textBox1.Text); lvi.SubItems.Add(subjects1); listView1.Items.Add(lvi); students.Add(new student { nazwisko = textBox1.Text, subjects1 = subjects }); }
Code:
//upon clicking the remove button on a selected listview item if (listView1.SelectedItems.Count != 0) { foreach (ListViewItem lvi in listView1.SelectedItems) { lvi.Remove(); } }
Comment