2 Answers, 1 is accepted
Hi, Udo,
If you want to load the images from a file path that is stored in the database, I believe that the following forum thread shows a sample approach that may fit your requirement:
https://www.telerik.com/forums/have-image-file-path-display-column-with-image
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi there,
Thanks for your help.
Since I'm unfortunately not a professional, I need help again.
The images are not displayed in the correct size.
Private Sub rgvObjektdaten_CreateCell(sender As Object, e As GridViewCreateCellEventArgs) Handles MasterTemplate.CreateCell
If TypeOf e.Row Is GridDataRowElement AndAlso TypeOf e.Column Is GridViewDataColumn AndAlso (CType(e.Column, GridViewDataColumn)).Name = "Bildpfad" Then
e.CellType = GetType(CustomGridImageCellElement)
End If
End Sub
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Windows.Forms
Imports Telerik.WinControls
Imports Telerik.WinControls.Primitives
Imports Telerik.WinControls.UI
Class SurroundingClass
Private Sub radGridView1_CreateCell(ByVal sender As Object, ByVal e As GridViewCreateCellEventArgs)
If TypeOf e.Row Is GridDataRowElement AndAlso TypeOf e.Column Is GridViewDataColumn AndAlso (CType(e.Column, GridViewDataColumn)).Name = "Bildpfad" Then
e.CellType = GetType(CustomGridImageCellElement)
End If
End Sub
Public Class CustomGridImageCellElement
Inherits GridDataCellElement
Private _imagePrimitive As ImagePrimitive
Public Sub New(column As GridViewDataColumn, row As GridRowElement)
MyBase.New(column, row)
End Sub
Protected Overrides Sub CreateChildElements()
MyBase.CreateChildElements()
_imagePrimitive = New ImagePrimitive()
_imagePrimitive.Margin = New Padding(3)
Me.Children.Add(_imagePrimitive)
Me.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren
End Sub
Protected Overrides Sub SetContentCore(value As Object)
If Me.Value IsNot Nothing AndAlso Not Me.Value.Equals(DBNull.Value) AndAlso File.Exists(Me.Value.ToString()) Then
_imagePrimitive.Image = Bitmap.FromFile(Me.Value.ToString())
Else
_imagePrimitive.Image = Nothing
End If
End Sub
End Class
End Class
Thanks
Hi there,
here's another oddity.
When I scroll, the images disappear from the cells and the path to the image appears.
Hi, Udo,
I created a sample project that is based on the approach used in this forum post: https://www.telerik.com/forums/have-image-file-path-display-column-with-image.
In order to be able to see correctly the images we need to have adjusted row height:
Me.RadGridView1.TableElement.RowHeight = 60
To fix this I have replaced the ImagePrimitive in the custom cell with a LightVisualElement and set its ImageLayout to Zoom.
Now the images are fully visible in the cell. If you need to display bigger images, you can set the RowHeight to another value or set the AutoSizeRows property of RadGridView to True.
Here is the updated implementation of the custom image cell:
Public Class CustomGridImageCellElement
Inherits GridDataCellElement
Private _imageElement As LightVisualElement
Public Sub New(ByVal column As GridViewDataColumn, ByVal row As GridRowElement)
MyBase.New(column, row)
End Sub
Protected Overrides Sub CreateChildElements()
MyBase.CreateChildElements()
_imageElement = New LightVisualElement()
_imageElement.DrawImage = True
_imageElement.Margin = New Padding(3)
_imageElement.ImageLayout = ImageLayout.Zoom
Me.Children.Add(_imageElement)
Me.AutoSizeMode = RadAutoSizeMode.WrapAroundChildren
End Sub
Protected Overrides Sub SetContentCore(ByVal value As Object)
If Me.Value IsNot Nothing AndAlso Not Me.Value.Equals(DBNull.Value) AndAlso File.Exists(Me.Value.ToString()) Then
_imageElement.Image = Bitmap.FromFile(Me.Value.ToString())
Else
_imageElement.Image = Nothing
End If
End Sub
End Class