private void OnAddActor(object sender, EventArgs e) { DialogRename dialog = new DialogRename(project.GenerateNewActorID()); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Actor actor = new Actor(); actor.ID = dialog.NewID; actor.Name = dialog.NewID; project.ListActors.Add(actor); (listBoxActors.DataSource as BindingSource).ResetBindings(false); listBoxActors.SelectedIndex = listBoxActors.Items.Count - 1; if (currentActor == null) //SelectedIndex will be already set on first insertion, this is a fallback for this special case { currentActor = listBoxActors.SelectedValue as Actor; RefreshActorView(); } SetDirty(); } }