Example E694
Visible to All Users

WinForms Data Grid - Drag-and-drop data rows from one grid to another

Note

In v17.2+, you can attach Drag And Drop Behavior to Grid controls to enable drag-and-drop without writing additional code.

This example demonstrates how to use traditional Drag events to allow users to drag data rows from one grid and drop them onto another grid control.

Files to Review

Documentation

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; using System; using System.Data; namespace DragDropTwoGrids { public partial class Form1 : DevExpress.XtraEditors.XtraForm { public Form1() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); DataTable table = FillTable(); SetUpGrid(gridControl1, table); SetUpGrid(gridControl2, table.Clone()); } public DataTable FillTable() { DataTable table = new DataTable(); table.Columns.Add("Column"); for (int i = 1; i <= 5; i++) table.Rows.Add(new object[] { "Item " + i.ToString() }); return table; } public void SetUpGrid(GridControl grid, DataTable table) { GridView view = grid.MainView as GridView; grid.DataSource = table; view.OptionsBehavior.Editable = false; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.