How to Set a Collection of Custom Controls from the property GridView in c# -
i have observablecollection of mysearchfields, on custom form, lets customform declare below:
private observablecollection<mysearchfields> _mysearchfields = new observablecollection<mysearchfields>(); [designerserializationvisibility(designerserializationvisibility.content)] [category("myframework")] public observablecollection<mysearchfields> mysearchfields { => _mysearchfields; }
and on main form inherits customform, when i'm on designer view , go propertygrid window select controltype combobox , select datasource, valuemember , display member. issue not set datasource,valuemember or displaymember. why happen? missing something?
public class mysearchfields { public enum mycontroltypes { mytextbox, mydatetimepicker, mylbcombobox } private mycontroltypes _mycontroltype = mycontroltypes.mytextbox; public mycontroltypes mycontroltype { => _mycontroltype; set { _mycontroltype = value; switch (_mycontroltype) { case mycontroltypes.mytextbox: { mycontrol = new textbox(); break; } case mycontroltypes.mylbcombobox: { mycontrol = new mylbcombobox(); break; } case mycontroltypes.mydatetimepicker: { mycontrol = new datetimepicker(); break; } } } } public control mycontrol { get; set; } public mysearchfields() { mycontrol = new control(); } }
your error on case switcher insert new mylbcombobox instead of combobox.
try initializing public control mycontrol { get; set; } proper setters , getters, private variable backs up,
furthermore use fullprop snippet of visual studio
just write "fullprop" , press 2 times tab, swapping around => , {} not nice.
Comments
Post a Comment