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. Image for the cookie policy date

How can I manually re-order records in a GridGroupingControl?

I want to manually reorder a selected row/record in a grid. I am using a GridGroupingControl to display nested tables from the data source. There are multiple nested tables in the grid.

I use the following code for obtaining the required record.

GridTable gt = mainGrid_.GetTable(lastSelectedRecordTable); // lastSelectedRecordTable is a string containing a table name and mainGrid_ is my GridGroupingControl variable
SelectedRecordsCollection rec = gt.SelectedRecords;

I get the required record/row at rec[0].Record after these lines but how should I proceed for manual reordering after that?

I have a button (BarItemUp_) that I intend to use for this purpose.


Also, when I do mainGrid_.Table.TableOptions.ListBoxSelectionMode = System.Windows.Forms.SelectionMode.MultiExtended, it works only on the top level table. How can I allow multiple selection in the child tables as well?

Thanks,
Swetaketu

1 Reply

MS Maniratheenam Sehar Syncfusion Team September 26, 2014 07:03 PM UTC

Hi Swetaketu Majumder, 

 

Thank you for your interest in Syncfusion products.

 

Query 1:

want to manually reorder a selected row/record in a grid.

Currently, we have to handle the Control.DragOver and Control.DragDrop events to do implement the Drag & Drop functionality in a GridGroupingControl. In a future release, the GridGroupingControl will be extended to directly support OLE Drag & Drop. TableControlMouseDown event is handled to begin the dragdrop operation which occurs only if the mousedown is over a RecordRowHeaderCell. In the Control.DragDrop event, the selected records are added to the target grid. With the cursor coordinates, the row and column of the target grid can be found. Using the row and column, the celltype can be found. If it is a RecordFieldCell , then the records in the DataObject can be pasted. See the below sample for code details.

Code Snippet[C#]:

 

private void grid_TableControlMouseDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlMouseEventArgs e)

{

GridGroupingControl grid = sender as GridGroupingControl;

if(grid!= null)

{

GridTableControl tableControl = grid.TableControl;

Point pt = new Point(e.Inner.X, e.Inner.Y);

int row, col;

if(tableControl.PointToRowCol(pt, out row, out col))

{

GridTableCellStyleInfo style = tableControl.Model[row, col];

//checking if the cell in which the MouseDown event is a RecordRowHeaderCell.

//If yes, then begins the DragDrop operation.

if((style.TableCellIdentity.TableCellType == GridTableCellType.RecordRowHeaderCell

|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordRowHeaderCell)

&& style.TableCellIdentity.DisplayElement.ParentRecord != null && style.TableCellIdentity.DisplayElement.ParentRecord.IsSelected())

{

DragDropEffects ef = tableControl.DoDragDrop(new DataObject(grid.Table.SelectedRecords), DragDropEffects.All);

if(ef == DragDropEffects.Move)

{

//need to delete selection if you want to support this

}

}

}

}

}

 

Moreover, we’ve added a UG link for your better convenience,

Link: http://help.syncfusion.com/ug/windows%20forms/default.htm#!documents/oledraganddrop.htm

 

Query 2:

How can I allow multiple selection in the child tables as well?

Multiple selection can be done in child table by accessing SelectedRecords collection of the desired child table. For your convenience, code snippet is given below,

Code Snippet[C#]:

 

//For Parent Table.

Record r1 = this.gridGroupingControl1.Table.Records[1];

Record r2 = this.gridGroupingControl1.Table.Records[2];

 

Table t = this.gridGroupingControl1.Table;

t.SelectedRecords.Add(r1);

t.SelectedRecords.Add(r2);

t.SelectedRecords.Add(r3);

//For Child Table.

Record cr1 = this.gridGroupingControl1.GetTable("Orders").Records[7];

Record cr2 = this.gridGroupingControl1.GetTable("Orders").Records[12];

 

this.gridGroupingControl1.GetTable("Orders").SelectedRecords.Add(or1);

this.gridGroupingControl1.GetTable("Orders").SelectedRecords.Add(or2);

 

For your better convenience, we’ve added an UG link below,

Link: http://help.syncfusion.com/ug/windows%20forms/default.htm#!documents/multiplerecordselect.htm

 

 

Please let us know, if you have any concerns.

 

Regards,

ManiRatheenam S


Loader.
Up arrow icon