[Sv] - addnewrow question?

Hi,
I use both previewrow and addnewrow.fixedbottom
When I add a new line, the addnewrow_Initializing event does not occur,   and it also doesn't add a checkbox to the new line.



When I double click this row then  addnewrowinitializing event is triggered (but no object return), please check this..



17 Replies

MA Mohanram Anbukkarasu Syncfusion Team June 26, 2020 11:19 AM UTC

Hi khanh dang, 
 
Thanks for contacting Syncfusion support.  

We have created a sample with checkbox column, preview row and AddNewRow at FixedBottom to replicate your scenario. We have checked the reported issue in our latest nuget version 18.1.0.59. Unfortunately we are unable to reproduce the issue in our end. The AddNewRowInitiating event raised with proper NewObject and the new row added with checkbox properly. Please find the sample we have used to test the reported issue from the following link. 


Please have a look at the above given sample and if the issue still occurs, please let us know if we have missed any customizations you have done in your application or try to reproduce the issue in the above given sample. It will be helpful for us to find the exact cause for the issue and to provide an exact solution at earlier. 

Regards, 
Mohanram A. 



TG The GridLock June 26, 2020 02:53 PM UTC

Hi Mohanram,
I have seen your file working, but I have not been able to find the cause, maybe I need more time.


SS Susmitha Sundar Syncfusion Team June 29, 2020 10:36 AM UTC

Hi khanh dang, 
 
Thanks for the update. 
 
We will wait to hear from you. 
 
Regards, 
Susmitha S 



TG The GridLock July 1, 2020 12:57 PM UTC

Hi,
There was a little problem with my class, I fixed the problem. Thanks for the sample file.
Edit: more question after add newrow!
It seems that this new row has not been added to datasource and datagrid.view
What conditions do it become a datarow?
do I need to double click to edit then select another row so that it becomes a valid row ? if I do not select another row sfdatagrid.selecteditem still returns null, 
my problem is that after the user has entered the data, they can click the button to execute code(ie I need after editing it will become valid row )


SS Susmitha Sundar Syncfusion Team July 1, 2020 03:28 PM UTC

Hi khanh dang, 
 
Thank you for the update. 
 
We are not clear with your requirement. Do you want to commit the new record values by button click? 
 
Please let us know, it will be helpful for us to check on it and provide you the solution at the earliest.   
Regards, 
Susmitha S 



TG The GridLock July 1, 2020 04:31 PM UTC

Hi susmitha, after click to addnewrow, i have newrow -> double click this row to edit data -> done. (note: I did not click to another row)
Now, How do I access this rowdata with button_click?




SS Susmitha Sundar Syncfusion Team July 2, 2020 02:55 PM UTC

Hi khanh dang,  

Thank you for the update. 

You can achieve your requested behavior “Get the add new row data in button click before click another row”, by get the new row value in SfDataGrid.RowValidating event and you can access through that variable. 


OrderInfo newRow; 
 
this.sfDataGrid1.AddNewRowPosition = RowPosition.FixedBottom; 
 
this.sfDataGrid1.RowValidating += SfDataGrid1_RowValidating; 
 
private void SfDataGrid1_RowValidating(object sender, RowValidatingEventArgs e) 
 { 
    newRow = e.DataRow.RowData as OrderInfo; 
 } 
 
 private void button1_Click(object sender, EventArgs e) 
 { 
     MessageBox.Show(newRow.OrderID.ToString()); 
 } 





Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 



TG The GridLock July 2, 2020 05:17 PM UTC

Hi Susmitha,
I have thought of this  but if it is not added to the datasource then when i need updating ID of all items will be difficult, if working on filterview it will disappear anytime, and affect other items.


SS Susmitha Sundar Syncfusion Team July 3, 2020 03:21 PM UTC

Hi khanh dang,  

We are not clear with your requirement. Can you please explain your exact requirement or modify our provided sample?  

It will be helpful for us to check on it and provide you the solution at the earliest.   

Regards, 
Susmitha S 



TG The GridLock July 3, 2020 10:48 PM UTC

Hi susmitha,

If I want to update the ID for all items now, can i do this?
1.  for each record in sfdatagrid.datasource
record.id = ...
    next
2. newRow1.id = ...
if I have multiple lines added perhaps I need to add each variable for each new line.
if I'm not mistaken it is accessible from view but not from datasource, but when clear filter it is no longer available.  Please clarify this.


MA Mohanram Anbukkarasu Syncfusion Team July 6, 2020 12:30 PM UTC

Hi Khanh dang, 

Thanks for the update. 

Query 
Response 
If I have multiple lines added perhaps I need to add each variable for each new line. 
It is not possible to add another row using AddNewRow without committing the current editing row. So it doesn’t require multiple variables for adding multiple rows. 
if I'm not mistaken it is accessible from view but not from datasource, but when clear filter it is no longer available.  Please clarify this. 
The new row added using AddNewRow will not be added to DataSource. It can be accessed only from SfDataGrid.View once the new row is committed.  
 
We are unclear with your statement “but when clear filter it is no longer available.” If you are facing any problem related to filter, kindly replicate the issue in the sample we have provided in our previous update or use the sample link given below. 
 

 

If we have misunderstood any of your update, Please revert to us with clear details about the problems you are facing and sample illustration to replicate the problems. It will be helpful for us to provide a prompt solution without further delay. 

Regards, 
Mohanram A. 



TG The GridLock July 6, 2020 02:12 PM UTC

Hi Mohanram ,
I see now, because if I add newrow to datagrid.view but on filterview, after clear the filter it seems to disappear, so I want to addnewrow will add new row to datasource,
Using addnewrow I won't need to add a new button.


MA Mohanram Anbukkarasu Syncfusion Team July 7, 2020 05:55 AM UTC

Hi Khanh dang, 

Thanks for the update. 

You can add the newly added row to the underlying data source collection by using SfDataGrid.RowValidated event as given in the following code example. 

Code example :  

this.sfDataGrid1.RowValidated += OnSfDataGrid1_RowValidated; 
 
private void OnSfDataGrid1_RowValidated(object sender, RowValidatedEventArgs e) 
{ 
    if(e.DataRow.RowType == RowType.AddNewRow) 
    { 
        list.Add(e.DataRow.RowData as OrderInfo); 
    } 
} 

We have prepared a simple sample using the above code example and it is available in the following link for your reference. 


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

Regards, 
Mohanram A. 



TG The GridLock July 7, 2020 09:46 AM UTC

Hi Mohanram 
I also thought of using this code before, but if I double click and select another row, it will add two rows similar(one for addnewrow and one for datasource), 


I have thought using combine:
 .view.records.removeat(lastrow)
then 
.datasouce add(new orderinfo)
but quite prolix. Maybe I'll use the button instead of this.


MA Mohanram Anbukkarasu Syncfusion Team July 8, 2020 12:43 PM UTC

Hi Khanh dang,  

Thanks for the update. 

You can achieve this without adding the row twice by canceling the addition of new row by AddNewRow as given in the following code example. 

Code example :  

this.sfDataGrid1.RowValidating += OnSfDataGrid1_RowValidating; 
 
private void OnSfDataGrid1_RowValidating(object sender, RowValidatingEventArgs e) 
{ 
   newRow = e.DataRow.RowData as OrderInfo; 
 
    if (this.sfDataGrid1.View.IsAddingNew) 
        this.sfDataGrid1.View.CancelNew(); 
 
    if (e.DataRow.RowType == RowType.AddNewRow) 
        list.Add(newRow); 
} 


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

Regards, 
Mohanram A. 



TG The GridLock July 8, 2020 06:48 PM UTC

Hi.
It seems this is what I need, I will consider it Mohanram!
Thanks you.


MA Mohanram Anbukkarasu Syncfusion Team July 9, 2020 10:33 AM UTC

Hi Khanh dang,   

Thanks for the update. 

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, 
Mohanram A. 


Loader.
Up arrow icon