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


How to show software keyboard when focusing textedit in Android

To show software keyboard when focusing textedit in Android you can use the snippet below.

Sample Java

myTextEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean focus) {
        if (focus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

How to use DebuggerDisplayAttribute in C# and VB.NET

If you want to change the information, the debugger variable window shows for your class, you can use the DebuggerDisplayAttribute.
Simply put the Attribut above your class declaration. The Value between {} are the name of the property or Field you want to show.

Sample C#

[DebuggerDisplay("Name = {Name}, Value = {Value}")]

Sample VB.NET

<DebuggerDisplay("Name = {Name}, Value = {Value}")>

Result

DebuggerDisplayAttribute

for more informations see the DebuggerDisplayAttribute Class MSDN Entry

How to list the avaiable fonts in Java

To list the avaiable fonts in Java you can use the following snippet.

Sample Java

GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
String fonts[] = g.getAvailableFontFamilyNames();
for (int Counter = 0; Counter < fonts.length;Counter++ ){
	System.out.println(fonts[Counter]);
}

How to show and select a file in explorer using C# and VB.NET

To show and select a file in explorer using C# and VB.NET you can use the following snippet.

Sample C#

private static void ShowFileInExplorer(string filePath)
{
	try
	{
		var winDir = Environment.GetEnvironmentVariable("windir");
		if (winDir != null)
		{
			var explorerPath = Path.Combine(winDir, @"explorer.exe");
			var arguments = String.Format("/select, {0}{1}{0}", (char)34, filePath);
			Process.Start(explorerPath, arguments);
		}
	}
	catch (Exception ex)
	{
		//handle the exception your way!
	}
}

Sample VB.NET

Private Shared Sub ShowFileInExplorer(filePath As String)
	Try
		Dim winDir = Environment.GetEnvironmentVariable("windir")
		If winDir IsNot Nothing Then
			Dim explorerPath = Path.Combine(winDir, "explorer.exe")
			Dim arguments = [String].Format("/select, {0}{1}{0}", Char(34), filePath)
			Process.Start(explorerPath, arguments)
		End If
	Catch ex As Exception
	        'handle the exception your way!
        End Try
End Sub

How to show and select a file in explorer using VBA

To show and select a file in explorer using VBA you can use the following snippet.
This snippet should also work in VB6.

Sample VBA

Dim path As String
Dim explorerPath As String
Dim cmd As String

explorerPath = Environ$("WINDIR") + "\Explorer.exe "
path = "C:\Users\Codesnippets\Desktop\test\Test.xml"
cmd = explorerPath + " /select , " + Chr(34) + path + Chr(34)
Call Shell(cmd, vbNormalFocus)

How to hide a console window in C# and VB.NET

To hide a console window in C# and VB.NET you can use the following snippet.

Sample C#

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

public static void SetConsoleWindowVisibility(bool show, IntPtr hWnd)
{
	try
	{
		ShowWindow(hWnd, !show ? 0 : 1);
	}
	catch (Exception ex)
	{
		//handle the exception your way
	}
}

Example usage

var hWnd = Window.FindWindow(null, Console.Title);
if (hWnd != IntPtr.Zero) 
{
	SetConsoleWindowVisibility(showWindows, hWnd);
}

Sample VB.NET

<DllImport("user32.dll")> _
Public Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll")> _
Public Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function

Public Shared Sub SetConsoleWindowVisibility(show As Boolean, hWnd As IntPtr)
	Try
		ShowWindow(hWnd, If(Not show, 0, 1))
	Catch ex As Exception
        'handle the exception your way
	End Try
End Sub

Example usage

Dim hWnd = Window.FindWindow(Nothing, Console.Title)
If hWnd <> IntPtr.Zero Then
	SetConsoleWindowVisibility(showWindows, hWnd)
End If