App crash when filter/sorting colunm which is dynamically add

I added Dynamically colunm ti grid using Dictionary. but when i click for sort or filter that newly added colunm then app crashed


5 Replies

MA Mohanram Anbukkarasu Syncfusion Team February 2, 2022 01:09 PM UTC

Hi Yogesh, 

The provided details are insufficient to check the issue in our end. We are unclear about your exact scenario and how you are adding columns dynamically using Dictionary. Please revert to us with more details about your scenario, details about the DataSource bounded to SfDataGrid and complete stack trace details of the exception. It will be helpful for us to find the exact cause for the issue and to provide a prompt solution.  

Regards, 
Mohanram A. 



YO Yogesh February 4, 2022 06:54 AM UTC

XAML.page

<Syncfusion:SfDataGrid Name="sfdatagrid"

                               AllowEditing="True"

                               AllowGrouping="True"

                               AutoGenerateColumns="False"

                               ColumnSizer="Star"

                               ItemsSource="{Binding StudentDetails}"

                               ShowGroupDropArea="True">

                <Syncfusion:SfDataGrid.Columns>

                    <Syncfusion:GridTextColumn MappingName="StudentID" />

                    <Syncfusion:GridTextColumn MappingName="StudentName" />


                    <Syncfusion:GridTextColumn MappingName="Major" />


                </Syncfusion:SfDataGrid.Columns>

            </Syncfusion:SfDataGrid>

XAML.cs

private void Button_Click(object sender, RoutedEventArgs e)

        {

            sfdatagrid.Columns.Add(new GridTextColumn()

            {

                HeaderText = "Subject1",

                MappingName = "Marks[Subject1]",

               // LineBreakMode = LineBreakMode.WordWrap,

                TextAlignment = TextAlignment.Center,

               // HeaderTextAlignment = TextAlignment.Center,

            });


            sfdatagrid.Columns.Add(new GridTextColumn()

            {

                HeaderText = "Subject2",

                MappingName = "Marks[Subject2]",

               // LineBreakMode = LineBreakMode.WordWrap,

                TextAlignment = TextAlignment.Center,

                //HeaderTextAlignment = TextAlignment.Center,

            });

        }


Model class

 public class Model : INotifyPropertyChanged

    {

        public int StudentID { get; set; }

        public string StudentName { get; set; }

        public int Age { get; set; }

        public string Major { get; set; }

        private Dictionary<string, int> _marks;

        public Dictionary<string, int> Marks

        {

            get

            {

                return _marks;

            }

            set

            {

                _marks = value;

                OnPropertyChanged("Marks");

            }

        }


        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propName)

        {

            if (PropertyChanged != null)

                PropertyChanged(this, new PropertyChangedEventArgs(propName));

        }

    }




Above is the sample code which we follow 

adding colunm in grid is working but sort/filter on that colunm get issue it crashes app



SS Sampathnarayanan Sankaralingam Syncfusion Team February 7, 2022 02:10 PM UTC

  
Hi Yogesh,  

You can avoid the application crash by setting UseBindingValue as true as shown in the below code snippet. 

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    dataGrid.Columns.Add(new GridTextColumn() 
    { 
        HeaderText = "Subject1", 
        MappingName = "Marks[Math]", 
        UseBindingValue = true, 
        TextAlignment = TextAlignment.Center, 
    });  
} 
 



Please refer the sample and let us know if you have any concerns. 

Regard, 
Sampath Narayanan.S 



YO Yogesh February 8, 2022 12:24 PM UTC

Hi,


Thank you Now it is working .No app crash


By assigning 

sfc.UseBindingValue = true;



SS Sampathnarayanan Sankaralingam Syncfusion Team February 9, 2022 02:35 PM UTC

Hi Yogesh,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.


Regards,

Sampath Narayanan.S


Loader.
Up arrow icon