// another class to dynamic custom type references class Person { public string firstName; public string middleName; public string lastName; public string GetFullName() { return firstName + " " + middleName + " " + lastName; } } </pre> // main class for showing the records in listView from a array/List<> <pre> public partial class MainUI : Form { List<Person> personsList = new List<Person>(); public MainUI() { InitializeComponent(); } private void addButton_Click(object sender, EventArgs e) { string firstName = firstNameTextBox.Text; string middleName = middleNameTextBox.Text; string lastName = lastNameTextBox.Text; Person newPerson = new Person(); newPerson.firstName = firstName; newPerson.middleName = middleName; newPerson.lastName = lastName; personsList.Add(newPerson); firstNameTextBox.Clear(); lastNameTextBox.Clear(); middleNameTextBox.Clear(); MessageBox.Show("saved"); } private void showAllButton_Click(object sender, EventArgs e) { foreach (Person newPerson in personsList) { ListViewItem item = new ListViewItem(); item.Text = newPerson.firstName; item.SubItems.Add(newPerson.middleName); item.SubItems.Add(newPerson.lastName); item.SubItems.Add(newPerson.GetFullName()); recordBookListView.Items.Add(item); } } }
Category / C#.net
Closing Form without affecting another Form in C#.Net
Form newForm1 = new Form(); this.Hide(); newForm1.showDialog(); this.Close();