.net - DataGridViewComboBox and Gridview -
i have gridview , have 1 column datagridviewtextboxcolumn. when assign datasource grid error:
datagridview default error dialog
the following exception occurred in datagridview:
system.formatexception: datagridviewcomboboxcell value not valid. to replace default dialog please handle dataerror event.
ok
i don't see why is..
this first class:
public class floraitem { public guid id { get; set; } public string name { get; set; } public int price { get; set; } public datetime expirationdate { get; set; } public category categoryitem { get; set; } } this class datasource of grid
the category class looks like:
public class category { public guid id { get; set; } public string name { get; set; } public bool addbreakstoprint { get; set; } } the datasource of dropdown (combobox) in grid have category datasource..
this initializecomponent function
private void initializecomponent() { this.components = new system.componentmodel.container(); this.grdfloraitems = new system.windows.forms.datagridview(); this.floraitembindingsource = new system.windows.forms.bindingsource(this.components); this.categorybindingsource2 = new system.windows.forms.bindingsource(this.components); this.lstcategories = new system.windows.forms.combobox(); this.label1 = new system.windows.forms.label(); this.namedatagridviewtextboxcolumn = new system.windows.forms.datagridviewtextboxcolumn(); this.pricedatagridviewtextboxcolumn = new system.windows.forms.datagridviewtextboxcolumn(); this.expirationdatedatagridviewtextboxcolumn = new system.windows.forms.datagridviewtextboxcolumn(); this.categoryitem = new system.windows.forms.datagridviewcomboboxcolumn(); ((system.componentmodel.isupportinitialize)(this.grdfloraitems)).begininit(); ((system.componentmodel.isupportinitialize)(this.floraitembindingsource)).begininit(); ((system.componentmodel.isupportinitialize)(this.categorybindingsource2)).begininit(); this.suspendlayout(); // // grdfloraitems // this.grdfloraitems.allowusertodeleterows = false; this.grdfloraitems.autogeneratecolumns = false; this.grdfloraitems.columnheadersheightsizemode = system.windows.forms.datagridviewcolumnheadersheightsizemode.autosize; this.grdfloraitems.columns.addrange(new system.windows.forms.datagridviewcolumn[] { this.namedatagridviewtextboxcolumn, this.pricedatagridviewtextboxcolumn, this.expirationdatedatagridviewtextboxcolumn, this.categoryitem}); this.grdfloraitems.datasource = this.floraitembindingsource; this.grdfloraitems.location = new system.drawing.point(12, 55); this.grdfloraitems.name = "grdfloraitems"; this.grdfloraitems.readonly = true; this.grdfloraitems.size = new system.drawing.size(652, 206); this.grdfloraitems.tabindex = 1; // // floraitembindingsource // this.floraitembindingsource.datasource = typeof(data.floraitem); // // categorybindingsource2 // this.categorybindingsource2.datasource = typeof(data.category); // // namedatagridviewtextboxcolumn // this.namedatagridviewtextboxcolumn.datapropertyname = "name"; this.namedatagridviewtextboxcolumn.headertext = "artikel"; this.namedatagridviewtextboxcolumn.name = "namedatagridviewtextboxcolumn"; this.namedatagridviewtextboxcolumn.readonly = true; this.namedatagridviewtextboxcolumn.width = 250; // // pricedatagridviewtextboxcolumn // this.pricedatagridviewtextboxcolumn.datapropertyname = "price"; this.pricedatagridviewtextboxcolumn.headertext = "prijs"; this.pricedatagridviewtextboxcolumn.name = "pricedatagridviewtextboxcolumn"; this.pricedatagridviewtextboxcolumn.readonly = true; // // expirationdatedatagridviewtextboxcolumn // this.expirationdatedatagridviewtextboxcolumn.datapropertyname = "expirationdate"; this.expirationdatedatagridviewtextboxcolumn.headertext = "verloop datum"; this.expirationdatedatagridviewtextboxcolumn.name = "expirationdatedatagridviewtextboxcolumn"; this.expirationdatedatagridviewtextboxcolumn.readonly = true; this.expirationdatedatagridviewtextboxcolumn.width = 150; // // categoryitem // this.categoryitem.datapropertyname = "categoryitem"; this.categoryitem.datasource = this.categorybindingsource2; this.categoryitem.displaymember = "name"; this.categoryitem.headertext = "categorie"; this.categoryitem.name = "categoryitem"; this.categoryitem.readonly = true; this.categoryitem.resizable = system.windows.forms.datagridviewtristate.true; this.categoryitem.sortmode = system.windows.forms.datagridviewcolumnsortmode.automatic; this.categoryitem.valuemember = "id"; // // editfloraitem // this.autoscaledimensions = new system.drawing.sizef(6f, 13f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.clientsize = new system.drawing.size(696, 273); this.controls.add(this.label1); this.controls.add(this.lstcategories); this.controls.add(this.grdfloraitems); this.name = "editfloraitem"; this.text = "editfloraitem"; this.controls.setchildindex(this.grdfloraitems, 0); this.controls.setchildindex(this.lstcategories, 0); this.controls.setchildindex(this.label1, 0); ((system.componentmodel.isupportinitialize)(this.grdfloraitems)).endinit(); ((system.componentmodel.isupportinitialize)(this.floraitembindingsource)).endinit(); ((system.componentmodel.isupportinitialize)(this.categorybindingsource2)).endinit(); ((system.componentmodel.isupportinitialize)(this.categorybindingsource1)).endinit(); ((system.componentmodel.isupportinitialize)(this.categorybindingsource)).endinit(); this.resumelayout(false); this.performlayout(); } this i'm stuck..
category needs collection (like list) not single item.
, call categories.
Comments
Post a Comment