This is a migrated thread and some comments may be shown as answers.

Add image in cell by clickevent

3 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cyril
Top achievements
Rank 1
Cyril asked on 24 Sep 2014, 06:45 AM
Hello,

I develop stock manager application for my company

I've a error message  converter can't convert

With VS2013 DataGridView, it's work but not with RadGridView

My code :

Private Sub MasterTemplate_CellClick(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick
        If e.ColumnIndex = 0 Then
            Dim oCell As GridViewCellInfo = DirectCast(RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex), GridViewCellInfo)
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim oImage As Image = Image.FromFile(OpenFileDialog1.FileName)
                oCell.Value = resizeImage(oImage, 48, 48)
            Else
                Dim oResult As DialogResult = MessageBox.Show("Voulez-vous supprimer l'icône associée à ce produit ?", "Icône du produit", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If oResult = Windows.Forms.DialogResult.Yes Then oCell.Value = Nothing
            End If
        End If
End Sub

Private Function resizeImage(ByVal oImage As Image, iWidth As Integer, iHeight As Integer) As Image
        Dim oSource As Bitmap = New Bitmap(oImage)
        Dim dScale As Double = oSource.Height / oSource.Width
        Dim oDest As New Bitmap(iWidth, iHeight)
        Dim gDest As Graphics = Graphics.FromImage(oDest)
        With gDest
            .InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
            .SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
            .CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
            .DrawImage(oSource, 0, 0, oDest.Width, oDest.Height)
            Return oDest
        End With
End Function





3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Sep 2014, 12:55 PM
Hello Cyril,

Thank you for writing.

In order this code to work you should use GridViewImageColumn. This column supports showing images and you can assign an image to it's cell value property.

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Cyril
Top achievements
Rank 1
answered on 25 Sep 2014, 02:16 PM
With code below, directly with cell value, I've same error message "converter can't convert" too

Private Sub MasterTemplate_CellClick(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellClick
        If e.ColumnIndex = 0 Then
            Dim oCell As GridViewCellInfo = DirectCast(RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex), GridViewCellInfo)
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim oImage As Image = Image.FromFile(OpenFileDialog1.FileName)
                oCell.Value = oImage
            Else
                Dim oResult As DialogResult = MessageBox.Show("Voulez-vous supprimer l'icône associée à ce produit ?", "Icône du produit", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If oResult = Windows.Forms.DialogResult.Yes Then oCell.Value = Nothing
            End If
        End If
End Sub
0
Dimitar
Telerik team
answered on 26 Sep 2014, 12:12 PM
Hello Cyril,

Thank you for writing back.

I have prepared a small sample to show you how this works on my side. Could you please check it and let me know how it fits in your case?

I am looking forward to your reply.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Cyril
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Cyril
Top achievements
Rank 1
Share this question
or