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 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 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 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