issue in unbound row

dear, 

I am using data table as source in datagrid. Data are displaying properly. Now I want to add new row as an unbound row. I already added Unbound row using

this.dataGrid.UnboundRows.Add(new GridUnboundRow() { Position = UnboundRowsPosition.Bottom });


Now I am going to save data in database but when I loop the grid, I don't get unbounded row count in 

var records = dataGrid.View.Records;

I am not using any view model here. How to add unbound row in view?

I think there is refreshing issue but please help me out how to get it.


 


  



5 Replies

LN Lakshmi Natarajan Syncfusion Team February 1, 2022 02:53 PM UTC

Hi Amish, 
 
The SfDataGrid allows you to get the unbound row details by using the GetUnboundRowAtRowIndex method. Please refer to the following code snippets for more reference, 
 
this.dataGrid.UnboundRows.Add(new GridUnboundRow() { Position = UnboundRowsPosition.Bottom }); 
 
var unboundRow = dataGrid.GetUnboundRowAtRowIndex(dataGrid.View.Records.Count + 1); 
if(unboundRow != null) 
{ 
    // You can get the unboundrow 
} 
 
You can also refer to our user guidance document regarding the same, 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 



AM Amish replied to Lakshmi Natarajan February 2, 2022 07:46 AM UTC

Dear, 

I am binding data table in data grid. for example there are 2 rows in data table. on binding data I get 2 count using

var records = dataGrid.View.Records ;

Now I want to add 3rd row as an unbound row. I added unbound row using  

this.dataGrid.UnboundRows.Add(new GridUnboundRow() { Position = UnboundRowsPosition.Bottom } );

As per documentation, I read, the unbound row added as separately but not in data grid because when I loop data grid as shown in following Code, I got only 2 records.

var records = dataGrid.View.Records;

int nColCount = dataGrid.Columns.Count;

foreach (var record in records) {

var dataRowView = record.Data as DataRowView;

if (dataRowView != null) {

for (int iCtr = 0; iCtr < nColCount; iCtr++) {

}

}

}      


As I understand that unbound row is actually not added/refreshed in our data grid. 

Now my requirement is that newly added unbound row should be added in data grid in such a way that when I loop grid, it should show me record count to 3

As per my requirement, SQL data table will not have fix no. of columns. So I am not using any view model.   

So first thing how to update/refresh data grid rows on adding unbound row with data?

Second thing, I have already added unbound row and added value in some of columns, now I go to 2nd row which is from data table source binding, on changing any column of this row will remove data of unbound row.

So please suggest me the complete solution for above both problem.     

   



SV Suja Venkatesan Syncfusion Team February 3, 2022 03:38 PM UTC

Hi Amish, 

Currently, we are checking the possibility to achieve your requirements. We will check completely and update you with further details in two business days (February 07, 2022). We appreciate your patience until then. 

Regards, 
Suja 



SV Suja Venkatesan Syncfusion Team February 7, 2022 03:35 PM UTC

Hi Amish, 

Regarding query “Get unboundrow values from View.Records” 

SfDataGrid.View.Records having the data related to collection which we binded to the Itemsource property. Please refer the below documentation link regarding view   
As we already suggested in our previous update, we get the unboundrow from SfDataGrid using GetUnBoundRow method. 
You can also refer to our user guidance document regarding the same,  

Regarding requirement “Changing any column of second row will remove data of unbound row” 

Currently, we are checking the possibility to achieve this requirement in our end. We will update you the further details on or before February 9,2022. We appreciate your patience until then. 

Regards, 
Suja 



SV Suja Venkatesan Syncfusion Team February 9, 2022 02:46 PM UTC

Hi Amish, 

As we mentioned in our previous update, SfDataGrid.View.Records having the data present in the collection which we binded to the Itemsource property. We should get the UnboundRows from SfDataGrid using GetUnBoundRow method. For populating data in UnboundRow based on second row value change, you can call SfDataGrid.InvalidateUnboundRow at runtime which invalidates the UnboundRow and QueryUnBoundRow gets triggered automatically where you can update the value of UnboundRow as needed. Please refer the following User documentation link regrading populating data in UnboundRow in the following link. 


Regards, 
Suja 


Loader.
Up arrow icon