How to manually populate a multicolumn devexpress TreeList using C# and VB.NET

To manually populate a multicolumn devexpress TreeList using C# and VB.NET you can use the snippet below.

Sample C#

using System;
using System.Collections.Generic;
using DevExpress.XtraEditors;

namespace de.Fesslersoft.MultiColumnTreeList
{
    public partial class Form1 : XtraForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var products = new List<ProductInfo>
            {
                new ProductInfo() {name = "Item1", desc = "Description1", price = Decimal.Zero}, 
                new ProductInfo() {name = "Item2", desc = "Description2", price = 3.0m}, 
                new ProductInfo() {name = "Item3", desc = "Description3", price = 5.45m}, 
                new ProductInfo() {name = "Item4", desc = "Description4", price = 12.32m}
            };


            foreach (var product in products)
            {
                var node = treeList1.AppendNode(null, null);
                node.SetValue(0, product.name);
                node.SetValue(1, product.desc);
                node.SetValue(2, product.price);
            }
        }
    }
    public class ProductInfo
    {
        public string name { get; set; }
        public string desc { get; set; }
        public decimal price { get; set; }
    }
}

Sample VB.NET

Imports System.Collections.Generic
Imports DevExpress.XtraEditors

Namespace de.Fesslersoft.MultiColumnTreeList
	Public Partial Class Form1
		Inherits XtraForm
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub Form1_Load(sender As Object, e As EventArgs)
			Dim products = New List(Of ProductInfo)() From { _
				New ProductInfo() With { _
					Key .name = "Item1", _
					Key .desc = "Description1", _
					Key .price = [Decimal].Zero _
				}, _
				New ProductInfo() With { _
					Key .name = "Item2", _
					Key .desc = "Description2", _
					Key .price = 3.0D _
				}, _
				New ProductInfo() With { _
					Key .name = "Item3", _
					Key .desc = "Description3", _
					Key .price = 5.45D _
				}, _
				New ProductInfo() With { _
					Key .name = "Item4", _
					Key .desc = "Description4", _
					Key .price = 12.32D _
				} _
			}


			For Each product As var In products
				Dim node = treeList1.AppendNode(Nothing, Nothing)
				node.SetValue(0, product.name)
				node.SetValue(1, product.desc)
				node.SetValue(2, product.price)
			Next
		End Sub
	End Class
	Public Class ProductInfo
		Public Property name() As String
			Get
				Return m_name
			End Get
			Set
				m_name = Value
			End Set
		End Property
		Private m_name As String
		Public Property desc() As String
			Get
				Return m_desc
			End Get
			Set
				m_desc = Value
			End Set
		End Property
		Private m_desc As String
		Public Property price() As Decimal
			Get
				Return m_price
			End Get
			Set
				m_price = Value
			End Set
		End Property
		Private m_price As Decimal
	End Class
End Namespace




How to drop Primary Key of a Table using MSSQL

To drop Primary Key of a Table using MSSQL you can use the snippet below.

Sample MSSQL

ALTER TABLE tblTest
DROP CONSTRAINT PK_tblTest
GO




How to download a file using Python

To download a file using Python you can use the snippet below.

Sample Python

import urllib.request
import shutil

# file_name = target file name
with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file:
    shutil.copyfileobj(response, out_file)




How to search stored procedures using MS-SQL

To search stored procedures using MS-SQL you can use the snippet below.

Sample MSSQL

SELECT Name FROM sys.procedures WHERE name LIKE '%StoredProcName%'




Top 10 reads of March 2015

These are the Top 10 reads of March 2015.


  • How to add or remove a class on hover using jQuery
  • How to use the HTML5 datalist tag
  • How to reload a ViewController in IOS using Objective-C
  • How to get current Domain of the PC in C# and VB.NET
  • What is the difference between typeof(), GetType() and IS in C# and VB.NET
  • How to split a delimited string to multiple rows using MSSQL
  • How to deep copy a IList in C# and VB.NET
  • How to make a multicolumn listbox in C# and VB.NET
  • How to open a Website in the default Browser in C# and VB.NET
  • How to delete .svn files and folders using Windows Batch Script



  • thanks to all visitors, bookmark us, share us, talk about us, Follow us!, Like us! let’s grow bigger!




    How to split a delimited string to multiple rows using MSSQL

    To split a delimited string to multiple rows using MSSQL you can use the snippet below.

    Sample MSSQL

    CREATE FUNCTION dbo.StringSplit
    (
        @Input       NVARCHAR(MAX),
        @Delimiter  NVARCHAR(255)
    )
    RETURNS TABLE
    AS
        RETURN (
    		SELECT Number = ROW_NUMBER() OVER (ORDER BY Number),
            Item FROM (
    					SELECT Number, Item = LTRIM(RTRIM(SUBSTRING(@Input, Number, CHARINDEX(@Delimiter, @Input + @Delimiter, Number) - Number)))
    					FROM (SELECT ROW_NUMBER() OVER (ORDER BY ao.[object_id])
    					FROM sys.all_objects AS ao CROSS APPLY sys.all_objects) AS n(Number)
    					WHERE Number <= CONVERT(INT, LEN(@Input))
    					AND SUBSTRING(@Delimiter + @Input, Number, 1) = @Delimiter
    				  ) AS item);
    GO
    




    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 delete .svn files and folders using Windows Batch Script

    to delete .svn files and folders using Windows Batch Script you can use the following snippet.

    Sample Windows Batch Script

    FOR /R "C:\Users\CodeSnippets.Fesslersoft.de\Documents\Visual Studio 2013\Projects\ConsoleApplication" %%X IN (.svn) DO (RD /S /Q "%%X" 2>nul)
    

    Replace C:\Users\CodeSnippets.Fesslersoft.de\Documents\Visual Studio 2013\Projects\ConsoleApplication with your Solution’s Path.




    What is the difference between typeof(), GetType() and IS in C# and VB.NET

    What is the difference between typeof(), GetType() and is?

  • typeof() takes a type name specified at compile Time.
  • GetType() gets the Type of an Object at runtime
  • is returns true if an instance is in the inheritance tree. Since the is Keyword is casting the object, you should use it with care.
  • here is an example.

    class Employee { } 
    class Developer : Employee { }
    
    void PrintTypes(Employee e) { 
        print(e.GetType() == typeof(Employee)) // false 
        print(e is Employee)                   // true 
        print(e.GetType() == typeof(Developer))    // true
    }
    




    How to add or remove a class on hover using jQuery

    To add or remove a class on hover using jQuery you can use the snippet below.

    Adding a Class

    See this JSFiddle for adding a CSS-Class.

    $('#test1').hover(function(){  $(this).addClass('hoverClass');});
    

    Removing a Class

    See this JSFiddle for removing a CSS-Class.

    $('#test1').hover(function(){  $(this).removeClass('hoverClass');});