marb
asked on
Check if object still exists
I've got a main dialog, which itself creates new dialogs. Every time I create a new dialog, I do this:
NoteForm note = new NoteForm();
noteObjects.Add(note);
note.Show();
That means that I save a reference to the dialog in an ArrayList called noteObjects. The dialogs can be minimized and hidden. I added a button in my main dialog that shows all dialogs. So what I do is iterating through the ArrayList and call:
for(i=0;i<noteObjects.Coun t;i++) {
((NoteForm)noteObjects[i]) .Show();
}
If a dialog has been closed, there are invalid entries in the array which cause a System.ObjectDisposedExcep tion
How can I remove array elements that have become invalid?
if ((NoteForm)noteObjects[i] == null) ... doesn't work.
Thanks for any suggestion,
Martin
NoteForm note = new NoteForm();
noteObjects.Add(note);
note.Show();
That means that I save a reference to the dialog in an ArrayList called noteObjects. The dialogs can be minimized and hidden. I added a button in my main dialog that shows all dialogs. So what I do is iterating through the ArrayList and call:
for(i=0;i<noteObjects.Coun
((NoteForm)noteObjects[i])
}
If a dialog has been closed, there are invalid entries in the array which cause a System.ObjectDisposedExcep
How can I remove array elements that have become invalid?
if ((NoteForm)noteObjects[i] == null) ... doesn't work.
Thanks for any suggestion,
Martin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
note.Closing += new System.ComponentModel.Canc
and added a event handler:
void NoteFormClosing(object sender, System.ComponentModel.Canc
{
noteObjects.Remove(sender)
}
It works fine. Thank you AlexFM!