如果用户有:
,我需要检查我的按钮如果未输入任何内容,则会显示错误消息框并退出该过程。
它还需要调用我的insertIntoArrayist()过程并将值传递给它并将新值插入到数组列表中。 然后调用我的populateActors()一个。
这是我到目前为止所拥有的:
public void ()
{
*snip*
}
目前很确定它会添加名称,但不会添加到正确的位置..例如,如果我想将名称“Bob Marley”添加到位置“1”,则需要进入数组的顶部。 代码可能还有其他一些错误,所以如果你看到任何让我知道的话请你!所有提示都表示赞赏:)
答案 0 :(得分:1)
按钮点击处理程序中的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();
}
}
每次单击按钮时都会检查条件,从而为用户提供解决问题的机会。
您的数组插入代码对我来说很合适。