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

Move a column in a DataGrid with a nested relation

I am trying to move columns in a DataGrid using Model.Cols.MoveRange methods It works fine in most cases but if I have a nested relation then it doesn''t work anymore... I made a try with the sample: ExpandGrid. I simply added a button (by pressing the button I just want to move column 3 to column 1): private void button1_Click(object sender, System.EventArgs e) { System.Console.WriteLine( gridDataBoundGrid1.Binder.InternalColumns.Count ); gridDataBoundGrid1.Model.Cols.MoveRange(3,1); } By doing that, I change the Binder.InternalColums and after one click, one column is missing!!! If I change the code to (by pressing the button I want to move column 1 to column 3): private void button1_Click(object sender, System.EventArgs e) { System.Console.WriteLine( gridDataBoundGrid1.Binder.InternalColumns.Count ); gridDataBoundGrid1.Model.Cols.MoveRange(1,3); } Now, I get an exception. System.ArgumentOutOfRangeException: L''index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection. Nom du paramètre : index at System.Collections.ArrayList.get_Item(Int32 index) at Syncfusion.Windows.Forms.Grid.GridBoundColumnsCollection.get_Item(Int32 index) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.ModelColsMoving(Object sender, GridRangeMovingEventArgs e) at Syncfusion.Windows.Forms.Grid.GridDataBoundGridModel.OnColsMoving(GridRangeMovingEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.RaiseColsMoving(GridRangeMovingEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelColOperations.RaiseMoving(GridRangeMovingEventArgs e) catched at Syncfusion.Windows.Forms.Grid.GridModelColOperations.RaiseMoving(GridRangeMovingEventArgs e) in :line 0 How can I do to move a column in a grid that contains a nested relation? Thanks in advance, Sebastien

4 Replies

AD Administrator Syncfusion Team March 2, 2005 05:05 PM UTC

To get this to work, I think you will have to collapse all expanded rows before you move the columns. You could test this out to see if your moving code works ok as long as there are no expanded rows. If it does work, then you could freeze the painting in the grid, collapse all rows, move the columns, and then restore the expand-state of the grid, and then unfreeze the painting and then redraw the grid. Here is a link to a forum thread that discusses how to do something like this. It has a sample that saves the expand state before a sort, freezes the painting, sorts the grid, and then resets the expand state. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11104


SE seb March 3, 2005 12:56 PM UTC

Thank you for your response. It was a good idea. Unfortunately, the problem occurs even if all the rows are collapsed. >To get this to work, I think you will have to collapse all expanded rows before you move the columns. You could test this out to see if your moving code works ok as long as there are no expanded rows. > >If it does work, then you could freeze the painting in the grid, collapse all rows, move the columns, and then restore the expand-state of the grid, and then unfreeze the painting and then redraw the grid. Here is a link to a forum thread that discusses how to do something like this. It has a sample that saves the expand state before a sort, freezes the painting, sorts the grid, and then resets the expand state. > >http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=11104


AD Administrator Syncfusion Team March 4, 2005 12:02 PM UTC

Try this.gridDataBoundGrid1.Model.Cols.MoveRange(4,2); instead of (3,1). Column 1 is the +/- column in an hierarchical grid.


SE seb March 11, 2005 05:05 PM UTC

You were right and the API Grid.GridHierarchyLevel.LayoutColumns() solved the other part of my problem. Thanks Clay!

Loader.
Live Chat Icon For mobile
Up arrow icon