ボタン クリック ハンドラの do-while ループは大きな問題です。
//This button needs to give the error if the name or position in the array are left blank//
private void btnInsert_Click(object sender, EventArgs e)
{
// BIG PROBLEM HERE!!!!
do
{
string message = "Invalid Name or Position entered.";
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
while (int.Parse(txtPosition.Text == null));
InsertIntoArrayList(actName, posNum);
PopulateActors();
}
ボタンが最初にクリックされたときに、int.Parse(txtPosition.Text == null)
条件が満たされていない場合は、エラーを修正する機会をユーザーに与えることなく、メッセージ ボックスが繰り返し表示されます。
代わりにこれを試してください:
//This button needs to give the error if the name or position in the array are left blank//
private void btnInsert_Click(object sender, EventArgs e)
{
if (int.Parse(txtPosition.Text == null)) {
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} else {
InsertIntoArrayList(actName, posNum);
PopulateActors();
}
}
これは代わりに、ボタンがクリックされるたびに状態をチェックし、ユーザーに問題を修正する機会を与えます。
あなたの配列挿入コードは私にはうまく見えます。