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

Columns order

Hi.

When I set AllowDraggingColumns to True, I can reorder Columns. Please advice me, how can I set the original Columns-order?

Thanks.

Regards,
Juraj

3 Replies

FP Farjana Parveen Ayubb Syncfusion Team June 17, 2014 01:19 PM UTC

Hi Juraj,

 

We analyzed your query. Initially you can save the column order before reordering the columns.

Please refer the following code snippet

 

Code Snippet:

Initially you can saving the column by using “this.dataGrid.Columns.ToList();

 

public partial class MainWindow : ChromelessWindow

    {

        public MainWindow()

        {

            InitializeComponent();

            this.dataGrid.Columns.ToList();

        }

    }

 

Regards,

Farjana Parveen A

 



JT Juraj Tomana June 23, 2014 12:41 PM UTC

Hi.

But how to load the saved state? 

I have tried this way:

       GridColumn[] definovaneStlpce = Columns.ToArray();
        Columns columns = new Columns();
        foreach (
          GridColumn gridColumn in definovaneStlpce.OrderBy(s => Array.IndexOf(_savedColumns, s.MappingName)))
          columns.Add(gridColumn);
        Columns = columns;

.. but nothing happened. Maybe it needs to be refreshed (I've tried View.Refresh(), InvalidateVisual(),...).


I have also tried another way:

        Columns.Clear();
        foreach (
          GridColumn gridColumn in definovaneStlpce.OrderBy(s => Array.IndexOf(_savedColumns, s.MappingName)))
          Columns.Add(gridColumn);

.... but following exception was thrown:
System.ArgumentOutOfRangeException occurred
  _HResult=-2146233086
  _message=1 out of range 0 to 0
  HResult=-2146233086
  IsTransient=false
  Message=1 out of range 0 to 0
Parameter name: from
  Source=Syncfusion.SfGrid.WPF
  ParamName=from
  StackTrace:
       at Syncfusion.UI.Xaml.ScrollAxis.DistanceRangeCounterCollection.CheckRange(String paramName, Int32 from, Int32 to, Int32 actualValue)
  InnerException: 


Thanks.
Regards,
Juraj


FP Farjana Parveen Ayubb Syncfusion Team July 1, 2014 12:08 PM UTC

Hi Juraj,

 

Sorry about the inconvenienced caused.

 

We analyzed your query. You can’t able to set the column property directly. You can load the saved column order by clearing the reorder and adding the saved column order.

 

Please refer the following code snippet and sample in the following location:

 

Code Snippet:

 

public List<GridColumn> columns;

        public MainWindow()

        {

            InitializeComponent();

            columns = sfdatagrid.Columns.ToList();

        }

 

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            sfdatagrid.Columns.Clear();

            foreach (GridColumn grid in columns)

            {

                sfdatagrid.Columns.Add(grid);

            }

        }

 

 

 

Regards,

Farjana Parveen A

 


Attachment: SfDataGridReorderingColumns_7708ea1f.zip

Loader.
Live Chat Icon For mobile
Up arrow icon