c# - BindingSource Get Current Row -
i cannot current row value. how can do?
bindingsource1.datasource = ldata; (ldata generic list)
public datarow currentrow { { int position = this.bindingcontext[bindingsource1].position; if (position > -1) { return ((datarowview)bindingsource1.current).row; } else { return null; } } }  i cannot current row :
 messagebox.show(currentrow["name"].tostring());  getting err: invalidcastexception, how can do? thanks.
you can't expect have datarow objects in bindingsource1.current if you're setting datasource list<t> instead datatable. in case bindingsource1.current contain instance of generic type.
i suppose you're initializing ldata this:
ldata = new list<t>();  the property should this:
public t currentrow { { int position = this.bindingcontext[bindingsource1].position; if (position > -1) { return (t)bindingsource1.current; } else { return null; } } }  and read value (assuming name property of t):
messagebox.show(currentrow.name);  not tested of course, should work. use debugger in following line see contents of current property like:
return (t)bindingsource1.current;  
Comments
Post a Comment