private void ContactDelete_button_Click(object sender, EventArgs e) { Book b = (Book)Books_ListBox.SelectedItem; if (b == null) { return; } int index = Contacts_ListBox.SelectedIndex; if (index < 0 || index >= b.getContacts().Count()) { return; } Contact c = b.getContacts()[index]; b.getContacts().RemoveAt(index); Contacts_ListBox.DataSource = null; Contacts_ListBox.DataSource = b.getContacts(); if (index >= b.getContacts().Count()) { index -= 1; } Contacts_ListBox.SelectedIndex = index; toDeleteContacts.Add(c); update(true); }
private void Books_ListBox_SelectedIndexChanged(object sender, EventArgs e) { Book b = (Book)Books_ListBox.SelectedItem; if (b == null) { return; } selectedBook = b; if (b.getContacts().Count() == 0) { selectedContact = null; } else { selectedContact = b.getContacts()[0]; Contacts_ListBox.SelectedItem = selectedContact; } Books_ListBox.SelectedItem = b; Contacts_ListBox.DataSource = b.getContacts(); }
public Contact getContactById(int id) { Book b = (Book)Books_ListBox.SelectedItem; foreach (Contact c in b.getContacts()) { if (c.id == id) { return(c); } } return(null); }
public void refreshContacts() { cm = (CurrencyManager)BindingContext[selectedBook.getContacts()]; cm.Refresh(); }