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

Add Row from SerialPort Incoming Data into SfDatagrid



I was able to successfully make the connection with serialport, and I receive the data without any problems, this data changes every second I want to take Every data that arrives, to a new Culumn and row of SFDatagrid.

3 Replies

MA Mohanram Anbukkarasu Syncfusion Team December 3, 2019 07:25 AM UTC

Hi Carlos, 

Thanks for contacting Syncfusion support. 

In SfDataGrid, the SfDataGrid.View.Records.CollectionChanged event will raise whenever any new record is added or removed from the underlying datasource and the SfDataGrid.View.RecordPropertyChanged event will raise when any existing data is changed. You can use these events to achieve your requirement as shown in the following code example.  

Code example :  

this.dataGrid.Loaded += OnDataGrid_Loaded; 
 
private void OnDataGrid_Loaded(object sender, RoutedEventArgs e) 
{ 
    this.dataGrid.View.Records.CollectionChanged += OnRecords_CollectionChanged; 
    this.dataGrid.View.RecordPropertyChanged += OnView_RecordPropertyChanged; 
} 
 
private void OnView_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    // Do you customization here. 
} 
 
private void OnRecords_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
    if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
    { 
        // Do you customization here. 
    } 
} 

Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



CB Carlos Branty replied to Mohanram Anbukkarasu December 4, 2019 12:40 AM UTC

Hi Carlos, 

Thanks for contacting Syncfusion support. 

In SfDataGrid, the SfDataGrid.View.Records.CollectionChanged event will raise whenever any new record is added or removed from the underlying datasource and the SfDataGrid.View.RecordPropertyChanged event will raise when any existing data is changed. You can use these events to achieve your requirement as shown in the following code example.  

Code example :  

this.dataGrid.Loaded += OnDataGrid_Loaded; 
 
private void OnDataGrid_Loaded(object sender, RoutedEventArgs e) 
{ 
    this.dataGrid.View.Records.CollectionChanged += OnRecords_CollectionChanged; 
    this.dataGrid.View.RecordPropertyChanged += OnView_RecordPropertyChanged; 
} 
 
private void OnView_RecordPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    // Do you customization here. 
} 
 
private void OnRecords_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
    if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 
    { 
        // Do you customization here. 
    } 
} 

Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Thanks for the support Mr.Mohanram A. I tried to attach the arduino data via serialport in SFDtagrid but I get an error "reference to object not set as
  instance of an object "I have attached the code I made would greatly appreciate your help, Thank you

Attachment: SrialPortToSFDataGrid_aa7932c3.zip


MA Mohanram Anbukkarasu Syncfusion Team December 4, 2019 12:46 PM UTC

Hi Carlos, 

Thanks for the update.  

We have checked the provided sample and the exception occurred in it. The null reference exception doesn’t arrive from the SfDataGrid. It occurs in the creation of the data using the SerialPort. Kindly check the creation of data from serial port to resolve the exception.  

Please let us know if your require any other assistance from us.  

Regards, 
Mohanram A. 


Loader.
Live Chat Icon For mobile
Up arrow icon