Wednesday, 15 January 2014

c# - Input string was not in a correct format in combobox -



c# - Input string was not in a correct format in combobox -

i have drop downwards list . need value of ddl when index changes.so :

private void cmbgroup_selectedindexchanged(object sender, eventargs e) { int id=int.parse(cmbgroup.selectedvalue.tostring()); //do id }

in form load fetch info :

goodgroups=objgoodgrouprepositoy.getall().tolist(); cmbgroup.datasource = goodgroups; cmbgroup.valuemember = "id"; cmbgroup.displaymember = "name";

i have such info in database :

id serial name 1 121 g1 2 123 g2

but got error before loading form :

input string not in right format

i got error in here in indexchange event of ddl

int id=int.parse(cmbgroup.selectedvalue.tostring());

the model :

public partial class goodgroup { public goodgroup() { this.goods = new hashset<good>(); } public int id { get; set; } public string serial { get; set; } public string name { get; set; } public virtual icollection<good> goods { get; set; } }

you should set displaymember , valuemember properties before datasource.

when datasource changed, or when displaymember or valuemember changed after datasource has been set, binding infrastructure forces command rebind

another way unsubscribe / subscribe event when modifying datasource.

c# winforms parsing converter

No comments:

Post a Comment