我在datagridview中显示了sql server数据库中的产品列表。
我的目标是通过图片框实现我可以为每个产品分配图像,这可以通过打开我的文件以选择图像的按钮来实现。加载图像后,保存按钮将执行其任务。
Private Sub btnFoto_Click(sender As Object, e As EventArgs) Handles btnFoto.Click
Dim openfile As New OpenFileDialog()
openfile.ShowDialog()
ruta = openfile.FileName
Try
PictureBox1.Image = Image.FromFile(ruta)
Catch ex As Exception
PictureBox1().Image = Image.FromFile(CurDir() + "\imagen\sin.png")
End Try
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Try
PictureBox1.Image = Image.FromFile(ruta)
Catch ex As Exception
PictureBox1().Image = Image.FromFile(CurDir() + "\imagen\sin.png")
End Try
End Sub
Private Sub btnGuardar_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click
Try
My.Computer.FileSystem.CopyFile(ruta, CurDir() + "\imagen\" + ".jpg")
Catch ex As Exception
PictureBox1.Image = Image.FromFile(CurDir() + "\imagen\sin.png")
MsgBox("...")
End Try
End Sub
注意:图像已插入,但是它们在所有行中都已更改,我不知道如何一一分配
谢谢。