Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
How can i read an image from a datagridview
Can you help me??
Posted
Updated 15-Mar-15 6:44am
v2
Comments
Sergey Alexandrovich Kryukov 15-Mar-15 12:45pm    
What have you tried so far?
—SA
Member 11511197 15-Mar-15 13:59pm    
Thanks :) !! I already got it, but i'm now trying to read an imagem according to the selected row, can you help??
Member 11511197 15-Mar-15 14:02pm    
'Leitura e Impressão da Imagem
Try
Dim ColumnTypes As New ArrayList 'Tipo de Dados das Colunas
Dim ColumnLefts As New ArrayList 'Cordenada Esquerda das Colunas
Dim ColumnWidths As New ArrayList 'Largura das Colunas
Dim RowPos As Int16 'Posição Currente da Linha
Dim CellHeight As Int16 'Altura da Célula
'Antes de começar a primeira pagina, ele guarda o Tipo da Coluna
For Each GridCol As DataGridViewColumn In ListaClientes.ClientesDataGridView.Columns
ColumnTypes.Add(GridCol.GetType)
Next
Do While RowPos <= ListaClientes.ClientesDataGridView.Rows.Count - 1
Dim GridRow As DataGridViewRow = ListaClientes.ClientesDataGridView.Rows(RowPos)
Dim i As Integer = 0
For Each Cel As DataGridViewCell In GridRow.Cells
'Para a Coluna da Imagem
If ColumnTypes(i) Is GetType(DataGridViewImageColumn) Then
e.Graphics.DrawImage(Cel.FormattedValue, New Rectangle(MargemEsquerda, 64, 225, 199))
End If
i += 1
Next
MargemSuperior += CellHeight
RowPos += 1
Loop
Catch ex As Exception
MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
End Try

1 solution

Please see:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewimagecell%28v=vs.110%29.aspx[^].

Some explanations: you can assume that the runtime type of some cell is System.Windows.Forms.DataGridViewImageCell; if you are asking this question, it should imply that you take care about using corresponding column type or this cell type for a separate cell; and the cell contains valid image data. You can check ValueType for the cell and see what kind of data it is: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.valuetype(v=vs.110).aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900