Drag & drop functionalities to swap column.

2 posts, 0 answers
  1. Johny
    Johny avatar
    9 posts
    Member since:
    Nov 2009

    Posted 13 Jul 2010 Link to this post

    Hi Guys:

    I’m using telerik almost one year…. this is really an excellent tools for rapid development. However I’m facing a little issues and I’m stuck I can’t resolved this. The issues is I have a grid with five column, the first column contain the serial number of each record, and now I want to add drag & drop functionalities to swap column. For example I select the column number 5 and drag and drop it into the column 2 so I the column will swap and reorder the serial number, the column 5 will be column 2 and column will be column 5. How can I achieve this? I need your help / any suggestion.


    Md. Marufuzzaman

  2. Martin Vasilev
    Martin Vasilev avatar
    1061 posts

    Posted 16 Jul 2010 Link to this post

    Hi Johny,

    Thank you for writing.

    The described behavior is not supported in RadGridView. However, in the new version Q2 2010 we have added a new way to access the drag and drop services in RadGridView that allows you to implement your requirement. Please consider the following code as an example:
    RadGridViewDragDropService _ddService;
    GridViewColumn _draggedColumn;
    private void Form1_Load(object sender, EventArgs e)
        _ddService = this.radGridView1.GridViewElement.GetService<RadGridViewDragDropService>();
        _ddService.PreviewDragStart += new EventHandler<Telerik.WinControls.PreviewDragStartEventArgs>(_ddService_PreviewDragStart);
        _ddService.Stopping += new EventHandler<Telerik.WinControls.RadServiceStoppingEventArgs>(ddService_Stopping);
    void _ddService_PreviewDragStart(object sender, Telerik.WinControls.PreviewDragStartEventArgs e)
        GridCellElement draggedCell = e.DragInstance as GridCellElement;
        if (draggedCell != null)
            _draggedColumn = draggedCell.ColumnInfo;
    void ddService_Stopping(object sender, Telerik.WinControls.RadServiceStoppingEventArgs e)
        GridCellElement dropCell = _ddService.DropTarget as GridCellElement;
        if (_draggedColumn != null && dropCell != null)
            GridViewDataColumn dropColumn = dropCell.ColumnInfo as GridViewDataColumn;
            SwapColumns(_draggedColumn as GridViewDataColumn, dropColumn);
        e.Commit = false;
        _draggedColumn = null;
    private void SwapColumns(GridViewDataColumn col1, GridViewDataColumn col2)
        int index1 = this.radGridView1.Columns.IndexOf(col1);
        int index2 = this.radGridView1.Columns.IndexOf(col2);
        this.radGridView1.Columns.Insert(index1, col2);
        this.radGridView1.Columns.Insert(index2, col1);

    Let me know if you have any additional questions.

    Best wishes,
    Martin Vasilev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top