private void photoListView_SelectedIndexChanged(object sender, EventArgs e) { DialogResult ret = DialogResult.OK; Haggle.DataObject dObj; Int32 selectedIndex = -1; if (photoListView.SelectedIndices.Count != 1) { return; } selectedIndex = photoListView.SelectedIndices[0]; Debug.WriteLine("Clicked image " + selectedIndex); Debug.WriteLine("Selected count is " + photoListView.SelectedIndices.Count); dObj = ps.dataObjects[selectedIndex]; Debug.WriteLine("Picture filename is " + dObj.GetFileName()); Debug.WriteLine("Picture filepath is " + dObj.GetFilePath()); try { ShowImageWindow imgWin = new ShowImageWindow(new Bitmap(dObj.GetFilePath()), dObj.GetFileName()); ret = imgWin.ShowDialog(); } catch (Exception) { Debug.WriteLine("Could not show image window dialog"); return; } if (ret == DialogResult.Yes) { // Yes means we should delete the image. Debug.WriteLine("Deleting picture with index " + selectedIndex + " and filename " + dObj.GetFileName()); ps.hh.DeleteDataObject(dObj); ps.dataObjects.RemoveAt(selectedIndex); photoListView.Items.RemoveAt(selectedIndex); } }