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();
}
Was it helpful?

Solution

Close over the variable using a lambda:

EditButton.Click += (sender, args) => openEditor(temp);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top