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


New member
Apr 28, 2014
Programming Experience
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 ...


VB.NET Forum Moderator
Staff member
Aug 17, 2004
Sydney, Australia
Programming Experience
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.
Top Bottom