Problem opening image from listview control

Katipo

New member
Joined
Dec 25, 2005
Messages
4
Programming Experience
1-3
Hi,

I am have trouble with a little MDI imagprogram I am working on.
Obviously imagers are opening in separate child windows.

I have built a "browser" window which shows thumbnails of all the images in a user selected directory in a listview control. The idea is you click on a thumb and the file name is passed.

If I then try to open a second image nothing is selected in the listviw and I get an error message saying my selecteditems index is invalid.

How to I fix this?
 
You need to show us the code. It's going to be an issue with your code rather than some inherent .NET issue, so we need to see the code to know what's going wrong. Please just post the code for the relevant section.
 
Here is the code in question:

PrivateSub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim strFile AsString = ListView1.SelectedItems(0).Text
Dim strFileName AsString = strCurrentFilePath + "\" + strFile
mdiMain.LoadFromBrowser(strFileName)
Me.Close()
EndSub

The first time this code runs fine and the picture loads. However if I try to load a second image then (unless I close my image browser and reopen it) I get an error message saying 0 is not a valid index. My debugging indicates that the second mouse click on the list view is returning nothing, which will be why the index 0 is invalid.
 
I'm not sure how your app is structured such that closing and reopening forms should have an impact, but that code will work as long as there's an item selected, so just put an If statement in to test ListView1.SelectedItems.Count to see whether there is.
 
Back
Top