private void Main_SwapButton_Click(object sender, RoutedEventArgs e) { //Check if selected item is valid if (Main_ListBox.SelectedIndex > -1) { int swapIndex = Main_ListBox.Items.IndexOf(Main_SwapTextBox.Text); //Check if swap item is valid if (swapIndex > -1) { MGSOGlobals.SwapScript(Main_ListBox, Main_ListBox.SelectedIndex, swapIndex); } else { //If it isn't valid, it could be empty or just entered wrong if (Main_SwapTextBox.Text == "") { MessageBox.Show("Please enter the name of the script to swap in the text box below and select the other script in the dropdown.", "An error occurred"); } else { MessageBox.Show("Script by the name of " + Main_SwapTextBox.Text + " not found.", "An error occurred"); } } } }