/// <summary> /// Handler for when the user leaves focus on the drop item probability text box. Now we actually update the UI. /// </summary> private void dropItemsProbabilityTextBox_Leave(object sender, EventArgs e) { ExtraDropEntry entry = entriesListBox.SelectedItem as ExtraDropEntry; if (entry != null) { ExtraDropItem item = dropItemsListBox.SelectedItem as ExtraDropItem; if (item != null && dropItemsListBox.SelectedItem != null && dropItemsListBox.SelectedIndex >= 0) { // This ensures the list updates as well. dropItemsListBox.Items[dropItemsListBox.SelectedIndex] = item; } } }
private void dropItemsListBox_SelectedIndexChanged(object sender, EventArgs e) { ListBox listBox = sender as ListBox; if (listBox != null && listBox.SelectedItem != null && listBox.SelectedIndex >= 0) { ExtraDropItem item = listBox.SelectedItem as ExtraDropItem; if (item != null) { dropItemsIdTextBox.Text = item.Id.ToString(); dropItemsProbabilityTextBox.Text = item.Probability.ToString("0.0###############"); } } }
/// <summary> /// Handler for when the drop item probability text box is editted. Here, we will only update the probability in /// the entry and not the UI. This is because updating the UI forces the probability to get formatted, which /// makes it hard to type. /// </summary> private void dropItemsProbabilityTextBox_TextChanged(object sender, EventArgs e) { TextBox textBox = sender as TextBox; if (textBox != null) { // We'll only update the id if it is actually a valid int. This is because numbers tend to take more // than one keystrokes to type and can be easily typed incorrectly. float probability; if (float.TryParse(textBox.Text, out probability)) { ExtraDropEntry entry = entriesListBox.SelectedItem as ExtraDropEntry; if (entry != null) { ExtraDropItem item = dropItemsListBox.SelectedItem as ExtraDropItem; if (item != null) { entry.EditItemProbability(dropItemsListBox.SelectedIndex, probability); } } } } }