In the Insert Into ArrayList button’s click event handler, check to see if the user has: Entered a position in the Position textbox. Entered an actor’s name in the Actor Name textbox.
Check these textboxes to see if the user has entered a value. Do not worry if the user has entered an incorrect value, just that they have entered a value. If no text has been entered display relevant error messages in message box format and exit the method so no further processing takes place.
Follow this with a call to InsertIntoArrayList, passing these values and causing the insertion of the new value into the ArrayList.
Finally, call PopulateActors to update its items to reflect the change.
My code so far is not inserting into the array:
private void btnInsert_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtPosition.Text))
{
MessageBox.Show("Please enter a Position");
return;
}
if (string.IsNullOrEmpty(txtActorName.Text))
{
MessageBox.Show("Please enter an Actor Name");
return;
}
InsertIntoArrayList(txtActorName.Text, Position);
PopulateActors();
}
And the Methods used are:
void InsertIntoArrayList(string txtActorName, int txtPosition)
{
ArrayList ActorArrayList = new ArrayList();
ActorArrayList.Insert(txtActorName, txtPosition);
}
And:
void PopulateActors()
{
cboActor.Items.Clear();
foreach (string Actor in ActorArrayList)
{
cboActor.Items.Add(Actor);
}
}
Newbie Coder! Cheers for your help :)
ArrayListtoList<string>.ArrayListis an untyped list and really shouldn't be used when you know the type that the list should contain.