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
close icon

How to update cell value in new row ?

Hello Syncfusion,
SfDataGrid has two columns (GridTextColumn and GridButtonColumn).
In the SfDataGrid_CellButtonClick, I allow user to select a file from openFileDialog control and then I set Cell value of the GridTextColumn to the path of selected file.
This works fine for the added rows but not for the new row.

How can I access to cell of the adding new row for updating its contnent ?

Best regards

4 Replies

FP Farjana Parveen Ayubb Syncfusion Team August 23, 2019 10:33 AM UTC

Hi Cosyspro, 
 
Thank you for using Syncfusion support. 
 
By default, CellButtonClick event is raise for GridButtonColumn in AddNewRow, so you can set the value for the GridTextColumn in CellButtonClick event by using SetValue method in PropertyAccessProvider. It’s set the value for both DefaultRow and AddNewRow. 
 
Please refer the below code example 
 
sfDataGrid.CellButtonClick += SfDataGrid_CellButtonClick; 
private void SfDataGrid_CellButtonClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellButtonClickEventArgs e) 
{ 
    var fileContent = string.Empty; 
    var filePath = string.Empty; 
 
    using (OpenFileDialog openFileDialog = new OpenFileDialog()) 
    { 
        openFileDialog.InitialDirectory = "c:\\"; 
        openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
        openFileDialog.FilterIndex = 2; 
        openFileDialog.RestoreDirectory = true; 
 
        if (openFileDialog.ShowDialog() == DialogResult.OK) 
        { 
            filePath = openFileDialog.FileName; 
            sfDataGrid.View.GetPropertyAccessProvider().SetValue((e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData, "FilePath", filePath); 
        } 
    } 
 
 
 
 
 
Please let us know if you need any further details on this. 
 
Regards,
Farjana Parveen A
 



CO Cosyspro August 23, 2019 05:33 PM UTC

Dear Farjana,
Thank you for your response and I appreciate your help.

Your solution does not work when I click on "Click here to add new row" and then I click directly on Button. An exception is generated "(e.Record as Syncfusion.WinForms.DataGrid.DataRow).RowData == null".

However, it works when I double click or edit FilePath Cell before click on Button.

Question: Why the display text of the Button is empty after click on "Click here to add new row" and it appears after edit or double click PathFile Cell?

Regards


FP Farjana Parveen Ayubb Syncfusion Team August 26, 2019 12:37 PM UTC

Hi Cosyspro, 
 
Thank you for your update, please refer the below response. 
 
Why the display text of the Button is empty after click on "Click here to add new row" 
The cell values for the AddNewRow will be initialized only when the AddNewRow is initialized. AddNewRow initialization will be triggered only when any of the cell in AddNewRow starts editing. 
Display text appears after edit or double click PathFile Cell? 
Here, the AddNewRow will be initialized and the display text for button is appeared properly. 
 
We are considering this behavior as a bug and we have logged a report on this. The fix for the reported issue will be included in our upcoming Volume 3 release which may expected to roll out on end of September 2019. 
 
Also we have created feedback link for the reported issue and we request you to login to the below link to view further 
 
 
Note: The provided feedback link is private, and you need to login to view this feedback. 
 
Regards,  
Farjana Parveen A 



FP Farjana Parveen Ayubb Syncfusion Team September 23, 2019 10:02 AM UTC

Hi Cosyspro, 
 
We are glad to announce that our Essential Studio 2019 Volume 3 Beta Release version 17.3.0.9 is rolled out with the reported issue fix “Cell buttons are loaded in add new row improperly before add new row is initialized” and is available for download under the following link. 
 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon