I hope you help me with this. My application controls the database for alerts. When a warning appears in the database, my application will add it to the main form in the datagridview, and depending on its priority, it will also create a small winform popup with an event.
There is a button in datagridview to mark the warning as "seen", then it will update the database and whether it will be removed from the list. However, the pop-up form for this event is still open.
Does anyone know how to close this form? I need a way to find a specific form between possible open forms of a firewall.
The closest I came to is the following code:
private void closeForm(int id) { foreach (Form f in Application.OpenForms) { if (Convert.ToString(id) == f.Name) { this.Close(); } } }
This works until it closes the correct form. then it gives an error message: "The collection has been changed, the enumeration operation may not be performed." This view makes sense, but I just can't figure out how to do it.
I have a winform class called Alert
that creates new forms. As you can see, they will receive the standard text βAlarmβ and a unique name based on the alert identifier.
Alert alertform = new Alert(id); alertform.Name = formid; alertform.Text = "Alarm"; alertform.Show();
Hope someone has some good ideas on how I can do this. I searched, but cannot find a simple and elegant way to do this.
source share