Question how to update selected checkbox in listview and update it into database

siang93

New member
Joined
Apr 28, 2014
Messages
4
Programming Experience
Beginner
how to update selected checkbox in listview and update it into database? ..if got 3 rows of data and i selected 2 ,i want the selected row to be updated into database once i click a button ...
 
If you're working with data from a database then I would question why you're using a ListView rather than a DataGridView in the first place. If you're not using multiple views or grouping in the ListView then it's an inferior choice.

That said, if you're determined to use a ListView then I would suggest that you populate a DataTable from the database and then assign each DataRow to the Tag property of the corresponding ListViewItem. That way you maintain a relationship between the two via more than just index.

As always, if you want to do something with items that are checked then you loop through the CheckedItems collection. Checked is different to selected, so CheckedItems is different to SelectedItems. If you've taken my advice from the previous paragraph then you can access the corresponding DataRow via the Tag property of each checked item. Once the DataRows have been updated, you save the changes back to the database with a data adapter, just as you always do.
 
Back
Top