# .NET and More > Silverlight >  Put one graphic into a DataGrid

## HerkyBird

I have a DataGrid in a Silverlight project, fed by an ObservableCollection, and I'd like to have in one column an entry for each row that is either a particular graphic (same graphic for each item), or none.  I could use a similar-sized all-white graphic instead if that would be easier than a blank.

Searching on the internet I've found discussions of feeding graphics to the DataGrid from a SQL database and other similarly complex operations, but that's all far, far more complexity than I'm aiming for.  I'd only need the one (or two) small graphic files, and each cell in that column of the grid has either the graphic or nothing.  (Or it has the one graphic or the other, if that's a better way to go.)

Can somebody point me to a discussion of how to do this sort of thing in Silverlight?

Many thanks!

----------


## MattP

Is the image coming from a Byte() property or will it be a relative resource in your project?

I'm assuming you're using a TemplateColumn with an Image control in the DataGrid.

Assuming you're providing a byte array to the converter here's how you'd set up the converter to return a BitmapImage.  This also returns a generic N/A image from the images folder if the value you pass is Nothing.



```
Public Class ImageConverter
    Implements IValueConverter
    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object _
    Implements IValueConverter.Convert
        If value IsNot Nothing Then
            Dim bi As New Imaging.BitmapImage()
            bi.SetSource(New IO.MemoryStream(DirectCast(value, [Byte]())))
            Return bi
        Else
            Return New Imaging.BitmapImage(New Uri("../images/ImageNotAvailable.png", UriKind.Relative))
        End If
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object _
    Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
```

Here's the msdn link for IValueConverter for further reading: http://msdn.microsoft.com/en-us/libr...8VS.95%29.aspx

----------

