DataGrid Itemsource changed

Hi,

i would like to change the datasource of the grid, columns and value, is it possible as i have done like in the example?


Best regards

Gian Piero Truccolo


Attachment: ChangeDatasourceColumns_ebb65767.zip

1 Reply

VS Vijayarasan Sivanandham Syncfusion Team May 30, 2022 03:37 PM UTC

Hi Gian Piero Truccolo,

We suspect that your requirement is to change the datasource of the grid when changing the Source property bound with the ItemsSource property in SfDataGrid.

You can achieve this by implementing the Source property with INotifyPropertyChanged. Please refer to the below code snippet,

public class VIew : INotifyPropertyChanged

{

        private ObservableCollection<dynamic> _Source;

        public ObservableCollection<dynamic> Source

        {

            get

            {

 

                return _Source;

            }

            set

            {

                _Source = value;

                OnPropertyChanged("Source");

            }

        }

 

    public event PropertyChangedEventHandler PropertyChanged;

   

    public void OnPropertyChanged(string PropertyName)

    {

            if (PropertyChanged != null)

                PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));

    }

 

}


UG Link: https://help.syncfusion.com/wpf/datagrid/columns#autogeneratecolumns-with-different-modes

https://help.syncfusion.com/wpf/datagrid/data-binding

Please find the modified sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S


Attachment: ModifiedSample_abd820bf.zip

Loader.
Up arrow icon