Using the second example: private List _products = new List() Now if you're concerned about where the data is coming from and it needs to be saved to a specific location, for example - each checkbox is tied to a 'product' and the checkbox designates where or not the product is still in stock, then you will need to dynamically apply a name with cb.Name = "nameHere" and make it meaningful so you can check it in the event handler. handle your checking and saving logic here. Private void cb_CheckedChanged(object sender, EventArgs e) Or you can do it after it's been generated and implicitly create a handler to process all checkboxes in the form within the same handler like below: var cb = new CheckBox() Ĭb.CheckedChanged += new EventHandler(cb_CheckedChanged) There are a few ways you can create on the dynamic event handlers you can either do your 'logic' on creation, using anonymous delegates and handle events like below: var cb = new CheckBox() Also I haven't handled assigning your controls to a container or anything like that. It's hard to really suggest a foolproof method of doing this without seeing how your code is being generated, however I will give it a shot for you.įorewarning - I'm at work and this code likely will have 'issues' as I cannot compile and test. ![]() After which you can handle the saving process. ![]() ![]() You can do the same as Mamta D has suggested except when your form is generated create a handler for each type of control and subscribe all relevant controls to the handler.
0 Comments
Leave a Reply. |