/// <summary> /// Called as we click the 'New' button to add a new publisher /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bnNewPublisher_Click(object sender, EventArgs e) { FormAskInput1 askPublisher = new FormAskInput1("Please enter the name of a new Publisher", "New Publisher", "Publisher:"); if (askPublisher.ShowDialog() == DialogResult.OK) { // Ensure that this name is not already in our list and if not add and select it string newPublisher = askPublisher.ValueEntered(); UltraListViewItem itemToSelect = null; int index = lvPublishers.Items.IndexOf(newPublisher); if (index == -1) { index = lvPublishers.Items.Add(new UltraListViewItem(newPublisher, null)); } itemToSelect = lvPublishers.Items[index]; // Bring the new item into view and select it itemToSelect.BringIntoView(); lvPublishers.SelectedItems.Add(itemToSelect, true); } }
/// <summary> /// Called to add a new Publisher to the list of those available to filter on. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bnNewPublisher_Click(object sender, EventArgs e) { FormAskInput1 form = new FormAskInput1("Please enter a name for the new Publisher.", "New Publisher", "Name:"); if (form.ShowDialog() == DialogResult.OK) { string newPublisher = form.ValueEntered(); // Ensure that this value does not duplicate an existing publisher either in the available or selected lists foreach (string publisher in lbAvailablePublishers.Items) { if (newPublisher == publisher) { MessageBox.Show("The Publisher Specified already exists an has not been added.", "Publisher Exists"); return; } } // Ensure that this value does not duplicate an existing publisher in the selected lists foreach (string publisher in lbFilteredPublishers.Items) { if (newPublisher == publisher) { MessageBox.Show("The publisher specified already exists and has not been added.", "Publisher Exists"); return; } } // Ok this is a new Publisher so add it to the definitions file ApplicationDefinitionsFile definitionsFile = new ApplicationDefinitionsFile(); definitionsFile.SetSection(ApplicationDefinitionsFile.PUBLISHERS_SECTION); definitionsFile.SetString(newPublisher, "", true); // ...and add it to the 'available' publishers list lbAvailablePublishers.Items.Add(newPublisher); } }
/// <summary> /// Called as we click New to create a new supplier /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bnNewSupplier_Click(object sender, EventArgs e) { FormAskInput1 askSupplier = new FormAskInput1("Please enter the name of a new Supplier", "New Supplier", "Supplier:"); if (askSupplier.ShowDialog() == DialogResult.OK) { // Ensure that this name is not already in our list and if not add and select it string newSupplierName = askSupplier.ValueEntered(); int supplierIndex = cbSuppliers.FindStringExact(newSupplierName); if (supplierIndex != -1) { MessageBox.Show("This Supplier already exists and will be selected", "Supplier Already Exists"); cbSuppliers.SelectedIndex = supplierIndex; } else { // This is a new supplier - Add to the list and select it Supplier newSupplier = new Supplier(); newSupplier.Name = newSupplierName; ValueListItem newItem = cbSuppliers.Items.Add(newSupplier); cbSuppliers.SelectedItem = newItem; } } }