help with c# array -
i have datatable 2 columns. want store rows of each column in array can return rows each individual column. way believe can populate list box(the option text 1 column , option value other column).
here started out with:
public object dbaccess2() { arraylist arg = new arraylist(); datatable mytable = genericdataaccess.executeselectcmd("vehicle_getmakes"); foreach (datarow drow in mytable.rows) { arg.add(drow["vehiclemake"]); arg.add(drow["vehiclemakeid"]); } return arg.toarray(); }
you can make class hold each individual row in case , use list<t>
hold data, this:
public class vehicle { public string make { get, set }; public string makeid { get, set }; } .. list<vehicle> vehicles = new list<vehicle>(); .. foreach (datarow drow in mytable.rows) { vehicles.add( new vehicle { make = arg.add(drow["vehiclemake"]), makeid = arg.add(drow["vehiclemakeid"]) }); }
and later, can populate listbox list:
listbox.datasource = vehicles; listbox.displaymember = "make";
but think may want use listview probably.
Comments
Post a Comment