vb.net 如何在 gridview devexpress 中单击时在 pictureedit 和 picturebox 中显示图像
How to display image in pictureedit and picturebox when clicked in gridview devexpress in vb.net
我想在点击gridview devexpress时显示picturedit和picturebox中的图片。
我想在一个pictureedit和一个picturebox中点击path1列和path2列的单元格值时显示图像。
Public Class Form1
Private WithEvents dt As New DataTable
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PRODUCT.mdb"
Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path
Private Images As Hashtable = New Hashtable()
Private Sub LoadDataGridView()
Try
dt = New DataTable
Dim query = "select Code,Path1,Path2 FROM ITEM"
Using adapter As New OleDbDataAdapter(query, cn.ToString)
adapter.Fill(dt)
End Using
Me.GridControl1.DataSource = dt
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadDataGridView()
End Sub
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
Dim path1 As String = view.GetFocusedRowCellValue("Path1").ToString
Dim path2 As String = view.GetFocusedRowCellValue("Path2").ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End Sub
End Class
Capturegridview18022022
Captureerror18022022
使用 Click 事件而不是 RowCellClick
Private Sub GridView1_Click(sender As Object, e As RowCellClickEventArgs) Handles GridView1.Click
Dim path1 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path1"))
Dim path2 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path2"))
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End Sub
访问https://docs.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Grid.GridView.RowCellClick
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
If e.Column.FieldName = "Path1" Then
Dim path1 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
Else
If e.Column.FieldName = "Path2" Then
Dim path2 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End If
End If
End Sub
我想在点击gridview devexpress时显示picturedit和picturebox中的图片。 我想在一个pictureedit和一个picturebox中点击path1列和path2列的单元格值时显示图像。
Public Class Form1
Private WithEvents dt As New DataTable
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PRODUCT.mdb"
Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path
Private Images As Hashtable = New Hashtable()
Private Sub LoadDataGridView()
Try
dt = New DataTable
Dim query = "select Code,Path1,Path2 FROM ITEM"
Using adapter As New OleDbDataAdapter(query, cn.ToString)
adapter.Fill(dt)
End Using
Me.GridControl1.DataSource = dt
Catch myerror As OleDbException
MessageBox.Show("Error: " & myerror.Message)
Finally
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadDataGridView()
End Sub
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
Dim path1 As String = view.GetFocusedRowCellValue("Path1").ToString
Dim path2 As String = view.GetFocusedRowCellValue("Path2").ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End Sub
End Class
Capturegridview18022022
Captureerror18022022
使用 Click 事件而不是 RowCellClick
Private Sub GridView1_Click(sender As Object, e As RowCellClickEventArgs) Handles GridView1.Click
Dim path1 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path1"))
Dim path2 As String = (GridView1.GetRowCellValue(GridView1.FocusedRowHandle,"Path2"))
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End Sub
访问https://docs.devexpress.com/WindowsForms/DevExpress.XtraGrid.Views.Grid.GridView.RowCellClick
Private Sub GridView1_RowCellClick(sender As Object, e As RowCellClickEventArgs) Handles GridView1.RowCellClick
Dim view As GridView = TryCast(sender, GridView)
If e.Column.FieldName = "Path1" Then
Dim path1 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path1)), True, False)
Else
If e.Column.FieldName = "Path2" Then
Dim path2 As String = view.GetRowCellValue(e.RowHandle, e.Column).ToString
PictureEdit1.Image = Image.FromStream(New MemoryStream(File.ReadAllBytes(path2)), True, False)
End If
End If
End Sub