0

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();
}
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
user2952817
  • 223
  • 1
  • 3
  • 8

1 Answers1

2

Close over the variable using a lambda:

EditButton.Click += (sender, args) => openEditor(temp);
Servy
  • 202,030
  • 26
  • 332
  • 449
  • Thank you very much this worked exactly the way I needed it. do you have any tutorials or documentation about lambda as im not too familiar with the technique – user2952817 Nov 06 '13 at 21:54
  • @user2952817 Not really, but Google knows of a few thousand, I'm sure you can find one that you like, which is why I gave you the proper term, so you'll have something to search on. – Servy Nov 06 '13 at 21:56
  • @user2952817 looks like Bing or Google had been off. Even if that happened, we still have Yahoo!Search (my favourite search engine in the old days :) and many others. `Lambda express` is very easy to make familiar with. – King King Nov 06 '13 at 21:57