从ListView项目填充PictureBox

时间:2014-02-27 11:23:57

标签: vb.net listview datagridview populate

大家好,我需要一些帮助。我想从PictureBox填充我的picpreview ListView,但它显示NotSupportedException was unhandled The given path's format is not supported。文本框似乎工作正常,但我仍然无法检索我的图像文件。顺便说一句,图像是.gif

 Dim sql As String
    Dim ds As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim cmd As New OleDb.OleDbCommand
    Dim dr As OleDb.OleDbDataReader

Dim inc As Integer
Dim listselect As String
Private Sub get_data()
    Try
        lvroutine.Items.Clear()
        connection()
        sql = "SELECT * From tblprogram ORDER BY MUSCLEGROUP ASC"
        cmd = New OleDbCommand(sql, con)
        dr = cmd.ExecuteReader

        While dr.Read
            Dim lv As ListViewItem = lvroutine.Items.Add(dr("MUSCLEGROUP"))

            With lv.SubItems

                .Add(dr("EXERCISENAME"))
                .Add(dr("EQUIPMENT"))
                .Add(dr("PREVIEW"))

            End With
        End While
        con.Close()


    Catch ex As Exception
        Exit Try
    End Try
End Sub
Private Sub view_record()

    connection()

    listselect = lvroutine.SelectedItems.Item(0).Text

    sql = "SELECT * From tblprogram WHERE MUSCLEGROUP ='" & listselect & "'"
    cmd = New OleDbCommand(sql, con)
    dr = cmd.ExecuteReader

    If dr.Read Then
        txtmuscle.Text = dr("MUSCLEGROUP")
        editprogram.txtexname.Text = dr("EXERCISENAME")
        editprogram.txteq.Text = dr("EQUIPMENT")
        picpreview = dr("PREVIEW")


    End If
End Sub

Private Sub clientprogram_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call get_data()
    Call connection()

    sql = "Select * From tblprogram ORDER BY MUSCLEGROUP ASC"
    da = New OleDb.OleDbDataAdapter(sql, con)

    da.Fill(ds, "tblprogram")

    con.Close()
End Sub

Private Sub lvroutine_Click(sender As Object, e As EventArgs) Handles lvroutine.Click
    txtmuscle.Text = lvroutine.SelectedItems(0).SubItems(0).Text
    txtexercise.Text = lvroutine.SelectedItems(0).SubItems(1).Text
    txtequipment.Text = lvroutine.SelectedItems(0).SubItems(2).Text
    'picpreview.Image = Image.FromFile(lvroutine.SelectedItems(0).SubItems(3).ToString)<--- This is where the error is.

End Sub




End Class

1 个答案:

答案 0 :(得分:0)

首先,确保您的路径是正确的路径。有时死Visual Studio会把它抛出来。只需设置一个断点或在执行代码行(出现错误的行)之前打开一个MsgBox并查看它。

其次,您可以尝试加载位图:

picpreview.Image = Bitmap.FromFile(lvroutine.SelectedItems(0).SubItems(3).ToString)

另外,我不是100%肯定但不是.ToString方法吗?我来自C#世界,但我认为你必须在.ToString之后添加大括号:

picpreview.Image = Bitmap.FromFile(lvroutine.SelectedItems(0).SubItems(3).ToString**()**)

尝试一下,让我听听什么工作,或者,如果有的话,没有用。