How to export Gridview data to Excel using devexpress XtraGrid

To export Gridview data to Excel using devexpress XtraGrid have a look at the sample below.

Samples

C# Sample

VB.NET Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

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

Please rate this snippet

How to make a multicolumn listbox in C# and VB.NET

To make a multicolumn listbox in C# and VB.NET you can use the following snippet.
First you need to add the Columns to the Listview.

multicolumnslistviewcsharp_add

Adding columns to the Listview

Sample C#

listView1.Items.Add("Column1Text").SubItems.AddRange(new string[] { "col1;row1", "col2;row1", "col3;row1" });
listView1.Items.Add("Column2Text").SubItems.AddRange(new string[] { "col1;row2", "col2;row2", "col3;row2" });
listView1.Items.Add("Column3Text").SubItems.AddRange(new string[] { "col1;row3", "col2;row3", "col3;row3" });

Sample VB.NET

listView1.Items.Add("Column1Text").SubItems.AddRange(New String() {"col1;row1", "col2;row1", "col3;row1"})
listView1.Items.Add("Column2Text").SubItems.AddRange(New String() {"col1;row2", "col2;row2", "col3;row2"})
listView1.Items.Add("Column3Text").SubItems.AddRange(New String() {"col1;row3", "col2;row3", "col3;row3"})
multicolumnslistviewcsharp

Result: Listview with Multiple Columns

Please rate this snippet

How to remove columns from DataTable in C# and VB.NET

To remove columns from DataTable in C# and VB.NET you can use the snippet below.

Sample C#

DataTable dataTable;
dataTable.Columns.Remove("Columnname");
dataTable.Columns.RemoveAt(index);

Sample VB.NET

Dim dataTable As DataTable
dataTable.Columns.Remove("Columnname")
dataTable.Columns.RemoveAt(index)

Please rate this snippet

How to check if a column exists in MSSQL

To check if a column exists in MSSQL you can use the following snippet.

Sample MSSQL

SELECT name FROM sys.columns WHERE object_id = OBJECT_ID('Pricetable') AND name='Price'

Please rate this snippet

How to make a multicolumn listbox in VBA

To make a multicolumn listbox in VBA you can use the following snippet.
This snippet should also work in VB6.

Sample VBA

Option Compare Database
Option Explicit

Private Sub Form_Load()
    FillListbox
End Sub

Public Sub FillListbox()
Dim i As Integer

Listbox1.Clear
Listbox1.ColumnCount = 4

For i = 0 To 9
    Listbox1.AddItem "Row" + CStr(i) + "; Column1"
    Listbox1.List(i, 1) = "Row" + CStr(i) + "; Column2"
    Listbox1.List(i, 2) = "Row" + CStr(i) + "; Column3"
    Listbox1.List(i, 3) = "Row" + CStr(i) + "; Column4"
Next
End Sub

Please rate this snippet

How to list all columns from a table in MSSQL

To list all columns from a table in MSSQL you can use the following snippet.

Sample MSSQL

SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('TABLENAME') ORDER BY name ASC

If you are using Oracle, take a look at this snippet -> How to get all column names of a Table in Oracle

Please rate this snippet