We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Reordering rows

Thread ID:

Created:

Updated:

Platform:

Replies:

95287 Jun 30,2010 07:01 AM UTC May 28,2018 10:26 AM UTC WinForms 8
loading
Tags: Grouping
Genu Smith
Asked On June 30, 2010 07:01 AM UTC

Hi
How it is possible to reorder rows by drag& drop and four buttons(move up,down,first,last).Is it possible to add a shortcut key for moving a row. eg: when user clicks Alt + up key in a row ?

Regards

Jisha Joy [Syncfusion]
Replied On June 30, 2010 10:47 AM UTC

Hi Genu,

You can move rows in grid by clicking over the row header and dragging them out. Please make sure to set the below property setting to do this.

this.gridControl1.AllowDragSelectedRows = true;

You could make use of the following code to move up the current record.

private void button2_Click(object sender, EventArgs e)
{
int rowindex = this.gridControl1.CurrentCell.RowIndex;
int colindex= this.gridControl1.CurrentCell.ColIndex;
if(rowindex-1 !=0)
{
this.gridControl1.Rows.MoveRange(rowindex, rowindex - 1);
this.gridControl1.CurrentCell.MoveTo(GridRangeInfo.Cell(rowindex - 1, colindex));
}
}


You could make use of the following code to move down the current record.

private void button1_Click(object sender, EventArgs e)
{

int rowindex = this.gridControl1.CurrentCell.RowIndex;
int colindex = this.gridControl1.CurrentCell.ColIndex;
if (rowindex + 1 <= this.gridControl1.RowCount)
{
this.gridControl1.Rows.MoveRange(rowindex, rowindex + 1);
this.gridControl1.CurrentCell.MoveTo(GridRangeInfo.Cell(rowindex + 1, colindex));
}
}

You could use the follwing code to move the records up when Alt+Up key is pressed.

void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;

bool altKeyDown = (e.Modifiers & Keys.Alt) != Keys.None;
Keys keyCode = e.KeyCode & Keys.KeyCode;

if (keyCode == Keys.Up && altKeyDown)
{
int rowindex = this.gridControl1.CurrentCell.RowIndex;
int colindex = this.gridControl1.CurrentCell.ColIndex;
if (rowindex - 1 != 0)
{
this.gridControl1.Rows.MoveRange(rowindex, rowindex - 1);
this.gridControl1.CurrentCell.MoveTo(GridRangeInfo.Cell(rowindex , colindex));
}
}
}

Attached a sample that implements this.


Please let me know if this helps.

Regards,
Jisha





Jisha Joy [Syncfusion]
Replied On June 30, 2010 10:48 AM UTC

Hi Genu,

Please find the sample.

Regards,
Jisha



GcSample_5ec38d62.zip

Genu Smith
Replied On June 30, 2010 06:17 PM UTC

Hi
Thanks, it was what I need but with grid control not with GridGrouping. I will test your code with it.

Regards

Jisha Joy [Syncfusion]
Replied On July 1, 2010 04:06 AM UTC

Hi Genu,

The above provided code is for GridControl, not for GridGroupingCOntrol. Please try this and let me know if this helps.

Regards,
Jisha

Genu Smith
Replied On July 1, 2010 05:04 PM UTC

Hi
That doesn't work with gridgroupingcontrol. there is neither AllowDragSelectedRows attribute nor rows property.Please give me provided sample with gridgroupingcontrol.

Regards

Jisha Joy [Syncfusion]
Replied On July 2, 2010 12:01 PM UTC

Hi Genu,

Thank you for your update. In GridGroupingControl just displays data that is presented by the underlying datasource. So we need to reorder the rows in the the datasource to achieve the desired behavior.

Regards,
Jisha

raman
Replied On May 26, 2018 07:44 AM UTC

can we use drag and drop feature to reorder rows in grid control.

Thanks & Regards

Arulpriya Ramalingam [Syncfusion]
Replied On May 28, 2018 10:26 AM UTC

Hi Raman,   
   
Thanks for using Syncfusion products.   
   
The GridControl has the default support to re-order the rows by enabling the AllowDrop and AllowDragSelectedRows properties. Please make use of the below code and UG link,   
   
Code example   
   
//To enable the drag and drop to reorder the rows.   
this.gridControl1.AllowDrop = true;   
this.gridControl1.AllowDragSelectedRows = true;   
   
   
   
 
Please let us know, if you have any other queries. 
   
Regards,   
Arulpriya   


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;