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 create an alert dialog in Android

To create an alert dialog in Android you can use the following snippet.

Sample Java

new AlertDialog.Builder(this)
    .setTitle("Delete items")
    .setMessage("Are you sure you want to delete this items?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // YES
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // NO
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

Please rate this snippet

How to configure Conditional Mapping in AutoMapper in C# and VB.NET

To configure Conditional Mapping in AutoMapper in C# and VB.NET you can use the following snippet.

Sample C#

 Mapper.CreateMap<Source, Target>().ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Variable1 == "Value1" ? true : false));

Sample VB.NET

Mapper.CreateMap(Of Source, Target)().ForMember(Function(dest) dest.Value, Function(opt) opt.MapFrom(Function(src) If(src.Variable1 = "Value1", True, False)))

Please rate this snippet

How to create a folder in Java

To create a folder in Java you can use on of these 2 Methods

Sample Java

boolean done = (new File("directoryName")).mkdir();  // all ancestor directories must exist!
if (!done) {  
    // failed ()  
}  

Sample Java

boolean done = (new File("directoryName")).mkdirs(); // all directories will be created   
if (!done) {  
    // failed  
}  

Please rate this snippet

How to create a folder in C# and VB.NET

To create a folder in C# and VB.NET you can use the following snippet.

Sample C#

try
{
	const string path = @"C:\Users\Codesnippets\Desktop\Testfolder\Test1\Test2";
	Directory.CreateDirectory(path);
}
catch (Exception ex)
{
	//handle the exception your way
}

Sample VB.NET

Try
	Const  path As String = "C:\Users\Codesnippets\Desktop\Testfolder\Test1\Test2"
	Directory.CreateDirectory(path)
Catch ex As Exception
        'handle the exception your way
End Try

Please rate this snippet