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 select a item on rightclick using devexpress ListboxControl

To select a item on rightclick using devexpress ListboxControl you need to use the MouseDown Event.
See the samples below.

Sample C#

private void listBoxControl1_MouseDown(object sender, MouseEventArgs e)
{
	listBoxControl1.SelectedIndex = listBoxControl1.IndexFromPoint(new Point(e.X, e.Y));
}

Sample VB.NET

Private Sub listBoxControl1_MouseDown(sender As Object, e As MouseEventArgs)
	listBoxControl1.SelectedIndex = listBoxControl1.IndexFromPoint(New Point(e.X, e.Y))
End Sub

Please rate this snippet

How to change the BackgroundColor of a XtraGrid Grouprow using C# or VB.NET

To change the BackgroundColor of a XtraGrid Grouprow you need to use the Gridviews CustomDrawGroupRow Event.

Sample C#

private void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e)
{
	var converter = new ColorConverter();
	var convertFromString = converter.ConvertFromString("#ebebeb");
	if (convertFromString != null)
	{
		e.Appearance.BackColor = (Color) convertFromString;
	}
}

Sample VB.NET

Private Sub gridView1_CustomDrawGroupRow(sender As Object, e As RowObjectCustomDrawEventArgs)
	Dim converter = New ColorConverter()
	Dim convertFromString = converter.ConvertFromString("#ebebeb")
	If convertFromString IsNot Nothing Then
		e.Appearance.BackColor = DirectCast(convertFromString, Color)
	End If
End Sub

Please rate this snippet

How to get the selected row index in Devexpress Xtragrid Control using C# and VB.NET

To get the selected row index in Devexpress Xtragrid Control using C# and VB.NET you can use the snippet below.

Samples

Sample C#

Sample VB.NET

Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5not working .NET 4.6

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 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 get focusedrow cell value using Devexpress XtraGrid in C# and VB.NET

To get focusedrow cell value using Devexpress XtraGrid in C# and VB.NET you can use one of the following ways.

Samples

Sample C#

Sample VB.NET

 

Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5not working .NET 4.6

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 disable Devexpress Node Movement while Drag Drop in C# and VB.NET

To disable Devexpress Node Movement while Drag Drop in C# and VB.NET you can use the following snippet.

Sample C#

private void treeList1_DragOver(object sender, DragEventArgs e) 
{
	e.Effect = DragDropEffects.None;
}

private void treeList1_CalcNodeDragImageIndex(object sender, CalcNodeDragImageIndexEventArgs e) 
{
	e.ImageIndex = -1;
}

Sample VB.NET

Private Sub treeList1_DragOver(ByVal sender As Object, ByVal e As DragEventArgs)
	e.Effect = DragDropEffects.None
End Sub

Private Sub treeList1_CalcNodeDragImageIndex(ByVal sender As Object, ByVal e As CalcNodeDragImageIndexEventArgs)
	e.ImageIndex = -1
End Sub

Please rate this snippet

How to use Doubleclick in Devexpress Gridview in C# and VB.NET

Using doubleclick events in the Devexpress Gridview Control is a simple task.
There are 2 different ways of doing this. The variant you choose, depends on the Gridview’s gridView.OptionsBehavior.Editable property. If this property is set to false you have to use the DoubleClick event. If this property is set to true you have to use the ShownEditor and HiddenEditor event. I will also give an example on how to combine both methods, if you are using both (true and false) on the gridView.OptionsBehavior.Editable.

Samples

OptionsBehavior.Editable set to False

C# Sample

VB.NET Sample

OptionsBehavior.Editable set to True

When inplace editing is enabled, a click on a grid cell activates the inplace editor (rowedit).
All mouse events will be sent to the editor and cannot be handled by the GridView directly. The DoubleClick event handler is no longer being executed.

C# Sample

VB.NET Sample

OptionsBehavior.Editable set to True or False at Runtime

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 use Node Doubleclick in Devexpress Treelist in C# and VB.NET

How to use Node Doubleclick in Devexpress Treelist in C# and VB.NET you can use the following snippet.

Sample C#

private void treeList1_DoubleClick(object sender, EventArgs e) 
{
	var treeList = sender as TreeList;
	var hitInfo = treeList.CalcHitInfo(treeList.PointToClient(MousePosition));
	if(hitInfo.Node != null) 
	{
		//do something
	}
}

Sample VB.NET

Private Sub treeList1_DoubleClick(sender As Object, e As EventArgs)
	Dim treeList = TryCast(sender, TreeList)
	Dim hitInfo = treeList.CalcHitInfo(treeList.PointToClient(MousePosition))
			'do something
	If hitInfo.Node IsNot Nothing Then
	End If
End Sub

Please rate this snippet