DataGrid and Image Data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Given
VB.Ne
Windows For
DataGri
Sql Server Table with Imag

Problem
Display Image in DataGri

Solution:???
 
Hi ClayB

Thanks for the feedback....Have already downloaded these samples (as well as ohters
and they provide about 95% solutiuon to the problem...

These and other samples get the image from either the imagelist control or IOStream files
NOT from SQL Server....

I have a stored procedure which amongst other things uses a user proc to determine the appropiate image..

The imageID and image (+ other data) is returned via the stored proc...

I could given the ImageID and some gludgey code get the appropiate image into an imagelist or from a IOStream and into the grid..

But given that I already have the image, it would seem better to bind it to the datagrid using a derived datagridcolumnstyle class...

Once again thanks for the feedback...

Regards....
 
Hi

Thanks for that pointer....

It provided a 98% solution...

Some comments were in German and the code was C# but after some further frustration a resul
was achieved in vb.net (shown below)

Once again thanks to ClayB and yourself... Great Help... Much appreciated..

Regards...

VB.Net Solution (or at least the significant bits)
Still some tinkering at the edges yet to do but the problem o
getting the image from SQL Server and displaying in the grid has been resolved

The three 'Paint' overrides are

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer

Dim backBrush As SolidBrush = New SolidBrush(Color.White
Dim byteArray() As Byte = getcolumnvalueatrow(source, rowNum
Dim imagePic As Bitmap = extractImage(byteArray

With
.FillRectangle(backBrush, bounds.X, bounds.Y, bounds.Width, bounds.Height
..DrawImage(imagePic, bounds.X, bounds.Y, imagePic.Width, imagePic.Height
End Wit
'/
End Su
Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal alignToRight As Boolean

Dim backBrush As SolidBrush = New SolidBrush(Color.White
Dim byteArray() As Byte = getcolumnvalueatrow(source, rowNum
Dim imagePic As Bitmap = extractImage(byteArray

With
..FillRectangle(backBrush, bounds.X, bounds.Y, bounds.Width, bounds.Height
..DrawImage(imagePic, bounds.X, bounds.Y, imagePic.Width, imagePic.Height
End Wit
'/
End Su

Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal BackBrush As Brush, ByVal ForeBrush As Brush, ByVal alignToRight As Boolean

Dim byteArray() As Byte = getcolumnvalueatrow(source, rowNum
Dim imagePic As Bitmap = extractImage(byteArray

With
..FillRectangle(BackBrush, bounds.X, bounds.Y, bounds.Width, bounds.Height
..DrawImage(imagePic, bounds.X, bounds.Y, imagePic.Width, imagePic.Height
End Wit
'/
End Su
'/
'/
'// The all important function cal
'/
'/
Private Function extractImage(ByVal Data() As Byte) As Bitma
Dim imageArray(Data.Length - 1) As Byt
Dim stream As IO.MemoryStrea

Tr
System.Buffer.BlockCopy(Data, 0, imageArray, 0, Data.Length
Catch ex As Exceptio
'// error handlin
End Tr
'/
stream = New IO.MemoryStream(imageArray
'/
extractImage = New Bitmap(stream
'/
End Functio
'/
'// PS some imports that you'll nee
Imports Syste
Imports System.Drawin
Imports System.Windows.Form
Imports System.Resource
Imports System.ComponentMode
 
Back
Top