Question

I have a winform that has several modules that are created dynamically based on information in a database. each of these modules has an edit button. I want to be able to pass in an object through to the click handler and then to the new form yet I cannot figure out how. Any help would be awsome here is what i have:

PingServer temp = manager.servers.ElementAt(i).Value;

EditButton.Click += new EventHandler(openEditor(temp));

private void openEditor(PingServer server)       
{            
    EditConnectionForm editConnection = new EditConnectionForm(server);
    editConnection.ShowDialog();
}
Était-ce utile?

La solution

Close over the variable using a lambda:

EditButton.Click += (sender, args) => openEditor(temp);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top