c# - How Can i move item collection in Winform Listbox1 to Listbox2? -
i doing student attendance project college in win form mysql(c#).
i ask hidden column in listbox got solution that.
updated query -
string myconstring = configurationmanager.connectionstrings["college_management_system.properties.settings.cmsconnectionstring"].connectionstring; mysqlconnection connection = new mysqlconnection(myconstring); string cnd1 = "select name,admin_no student_admision_master course='" + course_code + "' , year='" + year_code + "' , sem='" + semester_code + "' , batch='" + batch_code + "'"; mysqldataadapter da = new mysqldataadapter(cnd1, connection); connection.open(); dataset ds = new dataset(); mysqlcommand command = connection.createcommand(); da.fill(ds, "student_admision_master"); //datagridview1.datasource = ds.tables[formname]; listbox1.datasource = ds.tables[0].defaultview; listbox1.displaymember = "name"; listbox1.valuemember = "admin_no"; connection.close();
i got student name in listbox. but,.. listbox listbox moving code throw error,..
// listbox2 items r moved listbox 3
private void btn_tood_click(object sender, eventargs e) { int count = listbox2.items.count; (int = 0; < count; i++) { listbox3.items.add(listbox2.items[i].tostring()); } listbox2.items.clear(); }
// listbox3 items r moved listbox 2
private void btn_fromod_click(object sender, eventargs e) { int count = listbox3.items.count; (int = 0; < count; i++) { listbox2.items.add(listbox3.items[i].tostring()); } listbox3.items.clear(); }
// selected items move..
private void btn_toab_selected_click(object sender, eventargs e) { int count = listbox1.selecteditems.count; (int = 0; < count; i++) { listbox2.items.add(listbox1.selecteditems[i].tostring()); } (int = 0; < count; i++) { listbox1.items.remove(listbox1.selecteditems[0]); } } private void btn_fromab_selected_click(object sender, eventargs e) { int count = listbox2.selecteditems.count; (int = 0; < count; i++) { listbox1.items.add(listbox2.selecteditems[i].tostring()); } (int = 0; < count; i++) { listbox2.items.remove(listbox2.selecteditems[0]); } }
items collection cannot modified when datasource property set. in argument exception.
how can move item collection in listbox1 listbox2,.
and how can access particular valuemember(admin_no) listboxes.
bzs want save record based on admin_no.
is info enough or can add picture here,..
please give idea this!...
thanks in advance....
your list box databound - means, items in list box automatically managed binding manager. can not move items around way it.
instead, need modify underlying data source accordingly. means: not add/delete items to/from list boxes, to/from underlying data set.
every item in list box either datarow
or datarowview
, has row
property access underlying datarow
. once have access datarow
can determine field values using row['fieldname']
.
to move row 1 dataset another, have use importrow
method on destination table add row. have remove row source table. sample (which may have play around bit, haven't tried right now):
datarow row = listbox.selecteditem; /* above may need changed datarow row = (listbox.selecteditem datarowview).row; in case selecteditem datarowview instead of datarow */ destdataset.table.importrow(row); sourcedataset.table.remove(row);
Comments
Post a Comment