winforms - DataBind in C# - selectedvalue of ComboBox to Object property of a class -
i'm facing problem databinding in c# windows form project. used .net framework 4 client profile. , ide visual studio 2010 express edition c#. have class below.
public myclass() { name = string.empty; datatype = datatypes.bool; //property enum created me islist = false; filtervalue = new object(); }
then have profile.csv file. in 1 of form, have combobox , datasource datatable include data csv file.
private void form_load() { combobox combobox = new combobox(); this.controls.add(combobox); combobox.name = attribute.name.replace(" ", string.empty); combobox.displaymember = attribute.name; combobox.datasource = attributevaluedatasource.tables[tablename].defaultview; combobox.selectedindex = 0; }
then data binding on combo box class. data binding in method different above , combo box created dynamically, found combo box it's name in below method.
private void method_1 { control = this.controls.find(attrname, true); combobox specificcontrol = (combobox)control[0]; binding attributebinding = new binding(selectedvalue, attributeselectioncontroller.filterattributemodels[attributecount] , filtervalue, true, datasourceupdatemode.onpropertychanged, string.empty, f); attributebinding.controlupdatemode = controlupdatemode.onpropertychanged; specificcontrol.databindings.add(attributebinding); }
it seems fine till state. when binding event invoke , program flow go set property method, value.gettype() return system.data.datarowview type of selectedvalue of combobox item instead of string or integer or other datatype. have tried set value member combox while set datasource its. no help. 1 can on it? need urgent solution.
finally can figured out problem. in form load method, changed order of below lines.
combobox.displaymember = attribute.name; combobox.datasource = attributevaluedatasource.tables[tablename].defaultview;
as
combobox.datasource = attributevaluedatasource.tables[tablename].defaultview; combobox.displaymember = attribute.name; combox.valuemember = attribute.name;
then works. :)
**credit friend me.
Comments
Post a Comment