How to Display an Image in Devexpress XtraGrid Control using C# and VB.NET

To Display an Image in Devexpress XtraGrid Control using C# and VB.NET see the example below.

Sample C#

#region

using System.Data;
using System.Drawing;
using System.Windows.Forms;
using WindowsFormsApplication77.Properties;
using DevExpress.XtraEditors.Repository;

#endregion

namespace de.fesslersoft.XtraGridImageTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            gridControl1.DataSource = CreateTable(3);
            gridView1.Columns["Image"].ColumnEdit = new RepositoryItemPictureEdit();
        }

        private DataTable CreateTable(int rowCount)
        {
            var image = Resources.Image1;
            var tbl = new DataTable();
            tbl.Columns.Add("ID", typeof (int));
            tbl.Columns.Add("URL", typeof (string));
            tbl.Columns.Add("Image", typeof (Image));
            for (var i = 0; i < rowCount; i++)
            {
                tbl.Rows.Add(new object[] {i, "http://codesnippets.fesslersoft.de", image});
            }
            return tbl;
        }
    }
}

Sample VB.NET

#Region ""

Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports WindowsFormsApplication77.Properties
Imports DevExpress.XtraEditors.Repository

#End Region

Namespace de.fesslersoft.XtraGridImageTest
	Public Partial Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
			gridControl1.DataSource = CreateTable(3)
			gridView1.Columns("Image").ColumnEdit = New RepositoryItemPictureEdit()
		End Sub

		Private Function CreateTable(rowCount As Integer) As DataTable
			Dim image = Resources.Image1
			Dim tbl = New DataTable()
			tbl.Columns.Add("ID", GetType(Integer))
			tbl.Columns.Add("URL", GetType(String))
			tbl.Columns.Add("Image", GetType(Image))
			For i As var = 0 To rowCount - 1
				tbl.Rows.Add(New Object() {i, "http://codesnippets.fesslersoft.de", image})
			Next
			Return tbl
		End Function
	End Class
End Namespace

Result

XtraGrid ColumnImages

XtraGrid ColumnImages


Please rate this snippet

How to set the ios bookmark icon in HTML

To set the ios bookmark icon in HTML you can use the following snippet.

Sample HTML

<link rel="apple-touch-icon" href="iOs_Icon.png"/>

If your icon is already glossy, you can prevent the device from adding its own gloss by using.

Sample HTML

<link rel="apple-touch-icon-precomposed" href="iOs_Icon.png"/>

Please rate this snippet

How to rotate a image in C# and VB.NET

To rotate a image in C# and VB.NET you can use the following snippet.

Sample C#

public enum RotateMode
{
	Ninetee = 0,
	OneHundretEighty = 1,
	TwoHundredSeventy = 2,
}

public static Image RotateImage(Image myImage, RotateMode myRotatemode)
{
	var ret = myImage;
	switch (myRotatemode)
	{
		case RotateMode.Ninetee:
			ret.RotateFlip(RotateFlipType.Rotate90FlipNone);
			break;
		case RotateMode.OneHundretEighty:
			ret.RotateFlip(RotateFlipType.Rotate180FlipNone);
			break;
		case RotateMode.TwoHundredSeventy:
			ret.RotateFlip(RotateFlipType.Rotate270FlipNone);
			break;
	}
	return ret;
}

Sample VB.NET

Public Enum RotateMode
	Ninetee = 0
	OneHundretEighty = 1
	TwoHundredSeventy = 2
End Enum

Public Shared Function RotateImage(myImage As Image, myRotatemode As RotateMode) As Image
	Dim ret = myImage
	Select Case myRotatemode
		Case RotateMode.Ninetee
			ret.RotateFlip(RotateFlipType.Rotate90FlipNone)
			Exit Select
		Case RotateMode.OneHundretEighty
			ret.RotateFlip(RotateFlipType.Rotate180FlipNone)
			Exit Select
		Case RotateMode.TwoHundredSeventy
			ret.RotateFlip(RotateFlipType.Rotate270FlipNone)
			Exit Select
	End Select
	Return ret
End Function

Please rate this snippet

How to flip a image in C# and VB.NET

To flip a image in C# and VB.NET you can use the following snippet.

Sample C#

public enum FlipMode
{
	Horizontal = 0,
	Vertical = 1,
	Both = 2
}

public Image FlipImage(Image myImage, FlipMode myFlipmode)
{
	var ret = myImage;
	switch (myFlipmode)
	{
		case FlipMode.Horizontal:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX);
			break;
		case FlipMode.Vertical:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY);
			break;
		case FlipMode.Both:
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY);
			break;
	}
	return ret;
}

Sample Vb.NET

Public Enum FlipMode
	Horizontal = 0
	Vertical = 1
	Both = 2
End Enum

Public Function FlipImage(myImage As Image, myFlipmode As FlipMode) As Image
	Dim ret = myImage
	Select Case myFlipmode
		Case FlipMode.Horizontal
			ret.RotateFlip(RotateFlipType.RotateNoneFlipX)
			Exit Select
		Case FlipMode.Vertical
			ret.RotateFlip(RotateFlipType.RotateNoneFlipY)
			Exit Select
		Case FlipMode.Both
			ret.RotateFlip(RotateFlipType.RotateNoneFlipXY)
			Exit Select
	End Select
	Return ret
End Function

Please rate this snippet