I have a listview and will need to loop through the selected item collection. But I am getting an error below is my code:

```
 DataRowView drv;
 foreach(var current in lstValue.SelectedItems)
 {
        ListBoxItem li  = new ListBoxItem();
        drv = current as DataRowView;
        li.Content = Criteria + "=" + drv["CODE"];
        lstSelection.Items.Add(li);
 }

```

I get the error object reference not set to the instance of an object. This is the stack over flow link I already looked up 

[C# WPF - Get the selected items from a ListView](https://stackoverflow.com/questions/20901042/c-sharp-wpf-get-the-selected-items-from-a-listview)