这个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();
}
}
这不是检查条件的每个按钮被点击的时间,给用户有机会来解决该问题。
你的数组插入代码对我来说看起来很好。
我可以看到各种问题,但你需要分析自己正在发生的事情,而不是期待每个人都为你做你的工作。当你运行这个程序(假设它编译的时候),它会给你预期的输出吗? –
我不希望人们回答我,只是提示什么似乎是错误的,我可以自己回去编辑它,或者提示我应该如何去做......而不是我如何去做。 –