L
Larry
I've set up a list of image filesnames in a listview control(lvSrcFileList),
I'm using the selectedIndexChange event to select which file is being
displayed in a picturebox control(pbImagePreview). The first time a filename
is selected it works fine but if I try to select another filename the
program bombs with an exception error; flagging the line below "curntImage =
Image.FromFile(cpath). The listview is set for a single selection.
curntImage is declared global to the class as type image and curntSrcDir is
global and of type string. What I've found is that when I click on the
second item in the listview the event occurs but the selected items
collection acts as if it's empty. That isn't what I would expect and I not
sure why or what to do about it.
Here's the code I'm using:
Private Sub lvSrcFileList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lvSrcFileList.SelectedIndexChanged
' show a preview of the image file selected
Dim path, cpath As String
path = curntSrcDir & "\"
Dim it As ListViewItem
For Each it In Me.lvSrcFileList.SelectedItems
cpath = path & it.Text
Next
curntImage = Image.FromFile(cpath)
Me.pbImagePreview.Image = curntImage
Me.pbImagePreview.Show()
End Sub
-Larry
I'm using the selectedIndexChange event to select which file is being
displayed in a picturebox control(pbImagePreview). The first time a filename
is selected it works fine but if I try to select another filename the
program bombs with an exception error; flagging the line below "curntImage =
Image.FromFile(cpath). The listview is set for a single selection.
curntImage is declared global to the class as type image and curntSrcDir is
global and of type string. What I've found is that when I click on the
second item in the listview the event occurs but the selected items
collection acts as if it's empty. That isn't what I would expect and I not
sure why or what to do about it.
Here's the code I'm using:
Private Sub lvSrcFileList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lvSrcFileList.SelectedIndexChanged
' show a preview of the image file selected
Dim path, cpath As String
path = curntSrcDir & "\"
Dim it As ListViewItem
For Each it In Me.lvSrcFileList.SelectedItems
cpath = path & it.Text
Next
curntImage = Image.FromFile(cpath)
Me.pbImagePreview.Image = curntImage
Me.pbImagePreview.Show()
End Sub
-Larry