How to clear sorts of FlexGrid? .NET6

Posted by: info on 6 January 2023, 11:55 am EST

    • Post Options:
    • Link

    Posted 6 January 2023, 11:55 am EST - Updated 6 January 2023, 12:00 pm EST

    Hello.

    How to clear all sorts in code?

    C1.WPF.Grid.Ja 6.0.20223.380

  • Posted 8 January 2023, 10:53 pm EST

    Hi Mikihiro,

    You can use the Clear() method of the SortDescriptions collection of the CollectionView associated with FlexGrid to clear all the applied sorts. Please see the code below:

    ((ICollectionView)flexgrid.ItemsSource).SortDescriptions.Clear(); 

    Kindly refer to the attached sample for full implementation. (See ClearSortFlexgridNET6.zip)

    Thanks & Regards,

    Aastha

  • Posted 9 January 2023, 12:31 am EST - Updated 9 January 2023, 12:36 am EST

    Thank you for your reply.

    I can’t clear when Itemsource of the FlexGrid is an ObservableCollection.

    Also, how to clear the filters?

    This code doesn’t work for getting SortDescriptions.

    ICollectionView view = CollectionViewSource.GetDefaultView(flexgrid.ItemsSource);

    20230109 ClearSortFlexgridNET6.zip

  • Posted 10 January 2023, 4:57 am EST

    Hi Mikihiro,

    WPF Flexgrid internally uses ListCollectionView. Hence, you have to use the collection view to get the SortDescriptions and Filters applied to the Flexgrid control.

    We have updated the sample as per your requirement. Kindly refer to the attached sample. ( See ClearSortFlexgridNET6.zip)

    Thanks & Regards,

    Aastha

  • Posted 13 January 2023, 11:31 am EST - Updated 13 January 2023, 11:36 am EST

    Thank you for your reply.

    When an ItemSource is a ListCollectionView,

    Dragging Row doesn’t work.

          <c1:FlexGrid
                Name="flexgrid"
                Grid.Row="1"
                AllowDragging="Both"
                HeadersVisibility="All"
                ItemsSource="{Binding List}" />

    So, First, I would like to Request to fix this behavior.

    When an ItemSource is an ObservableCollection, ‘CollectionViewSource.GetDefaultView’ Method doesn’t get properties of ‘SortDescriptions’ and ‘Filter’.

    var listCollectionView = (ListCollectionView)CollectionViewSource.GetDefaultView(flexgrid2.ItemsSource);
    //listCollectionView.SortDescriptions Count is always 0.
    //listCollectionView.Filter is alwas null.

    Or, Second, I request

    • Clear Sorts Method
    • Clear Filters Method

    like this

    https://www.grapecity.com/componentone/docs/wpf/online-flexgrid/C1.WPF.FlexGridFilter.4.5.2~C1.WPF.FlexGrid.C1FlexGridFilter~Clear.html

    20230114ClearSortFlexgridNET6.zip

  • Posted 15 January 2023, 11:48 pm EST

    Hi,

    1. We have escalated this issue to the development team. Will let you know once they respond.[Internal Tracking Id - C1XAML-30987]
    2. FlexGrid 4.6.2 and FlexGrid Net6 have different architechture. Whereas FlexGrid Net6 uses ListCollectionView to group or sort data and you can clear SortDescriptions and GroupDescriptions accordingly.

    Best Regards,

    Nitin

  • Posted 22 January 2023, 4:16 pm EST

    Hi,

    We apologize for the delay.

    ListCollectionView doesn’t support moving item/row dragging.

    You can achieve RowDragging with the collection of SortDescriptions using C1DataCollection. C1DataCollection works similarly to ListCollectionView and supports moving items.

    public partial class MainWindow : Window
    {
        public ObservableCollection<Product> ProductList { get; set; } = new();
        public C1DataCollection<Product> List { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            ProductList.Add(new Product { Name = "aaa", Price = 1000, Weight = 100, Cost = 100, Volume = 10, Discontinued = false, Rating = 1 });
            ProductList.Add(new Product { Name = "bbb", Price = 500, Weight = 200, Cost = 300, Volume = 20, Discontinued = true, Rating = 20 });
            ProductList.Add(new Product { Name = "ccc", Price = 1500, Weight = 300, Cost = 20, Volume = 20, Discontinued = false, Rating = 5 });
            List = new C1DataCollection<Product>(ProductList);
        }
    
        private async void clrSortBtn_Click(object sender, RoutedEventArgs e)
        {
            await List.SortAsync();
            await List.RemoveFilterAsync();
        }
    }

    Please refer the attached sample : ClearSortFlexGridNet6_Mod.zip

    Best Regards,

    Nitin

  • Posted 23 January 2023, 12:46 pm EST

    Thank you.

    It works.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels