private void ButtonAdd_Click(object sender, EventArgs e) { using (DialogBoxPlayer DialogBox = new DialogBoxPlayer()) { DialogBox.Text = "Add Player"; DialogBox.ButtonConfirm.Text = "Add"; DialogBox.TextBoxPlayerName.Select(); while (true) { DialogResult Result = DialogBox.ShowDialog(); try { if (Result == DialogResult.OK) { long.Parse(DialogBox.TextBoxPlayerSteamID.Text); ListViewPlayers.Items.Add(new ListViewItem( new string[] { DialogBox.TextBoxPlayerName.Text, DialogBox.TextBoxPlayerSteamID.Text }) { Checked = DialogBox.CheckBoxPlayerEnabled.Checked }); } break; } catch { MessageBox.Show("The Steam ID is invalid.", "Could not add player.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void ButtonEdit_Click(object sender, EventArgs e) { foreach (ListViewItem Item in ListViewPlayers.SelectedItems) { using (DialogBoxPlayer DialogBox = new DialogBoxPlayer()) { int index = Item.Index; DialogBox.Text = "Edit Player"; DialogBox.ButtonConfirm.Text = "Confirm"; DialogBox.TextBoxPlayerName.Select(); DialogBox.TextBoxPlayerName.Text = ListViewPlayers.Items[index].SubItems[0].Text; DialogBox.TextBoxPlayerSteamID.Text = ListViewPlayers.Items[index].SubItems[1].Text; DialogBox.CheckBoxPlayerEnabled.Checked = ListViewPlayers.Items[index].Checked; while (true) { DialogResult Result = DialogBox.ShowDialog(); try { if (Result == DialogResult.OK) { long.Parse(DialogBox.TextBoxPlayerSteamID.Text); ListViewPlayers.Items[index].SubItems[0].Text = DialogBox.TextBoxPlayerName.Text; ListViewPlayers.Items[index].SubItems[1].Text = DialogBox.TextBoxPlayerSteamID.Text; ListViewPlayers.Items[index].Checked = DialogBox.CheckBoxPlayerEnabled.Checked; } break; } catch { MessageBox.Show("The Steam ID is invalid.", "Could not edit player.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }