clearly the object in: listBox1.SelectedItem
is of type: System.Data.DataRowView
so you simply cannot do:
(MyDataSet.BookRow)listBox1.SelectedItem;
the good news is that Delete or Remove methods work with the base class DataRow
and DataTable
so you don't really need to work at the BookRow
type level.
each DataRowView
contains a member called Row
which returns you the associated DataRow
, so you can use that one as your row and delete it directly from there or from the parent DataTable
.
I am not compiling the code so cannot say exactly but just try the following and adjust it if does not build fully:
((System.Data.DataRowView)listBox1.SelectedItem).Row.Delete();