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

How to get value from a cell in sfdatagrid?

Y try with this code, but not working, maybe this code is for Xamarin Forms
private void OnGetCellValue(object sender, EventArgs e)
        {
            foreach (var column in dataGrid.Columns)
            {
                if (column.MappingName == "CustomerID")
                {
                    var rowData = dataGrid.GetRecordAtRowIndex(2);
                    cellValue = dataGrid.GetCellValue(rowData, column.MappingName) as String;
                }
            }
            string value = cellValue.ToString();
        }

https://es.stackoverflow.com/questions/106565/c%C3%B3mo-obtener-los-valores-de-una-celda-o-fila-de-un-sfdatagrid-syncfusion-xamar

3 Replies

AN Ashok N Syncfusion Team October 3, 2017 01:17 PM UTC

Hi Customer,  
 
Thanks for contacting Syncfusion support. 
 
We have checked your code snippet and you are trying to convert object to string (SfDataGrid.GetCellValue method returns object) using as so values not convert to string. You can achieve your requirement by converting the value using ToString method, please refer the below code example: 
 
private void OnGetCellValue(object sender, EventArgs e) 
{ 
    string cellValue = null; 
    foreach (var column in sfGrid.Columns) 
    { 
        if (column.MappingName == "CustomerID") 
        { 
            var rowData = sfGrid.GetRecordAtRowIndex(2); 
            cellValue = sfGrid.GetCellValue(rowData, column.MappingName).ToString(); 
        } 
    } 
    string value = cellValue; 
} 
 
Regards, 
Ashok 



RS Rohan Singh February 14, 2024 05:43 AM UTC

Hi, I used method, I want to SetCellValue too, how can i Set Value of a SfDatagrid

? After GridViewTableData.view.Refresh i am getting Error




SY Suthi Yuvaraj Syncfusion Team February 16, 2024 03:00 PM UTC

Rohan Singh,

We have checked your requirement, you can set the cell value by SetValue, Please refer the below code snippet for more reference.

Code snippet:

dataGrid.CurrentCellActivated += DataGrid_CurrentCellActivated;

private void DataGrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs e)

{

    string newitem = "NewValue";

    var rowData = dataGrid.GetRecordAtRowIndex(e.CurrentRowColumnIndex.RowIndex);


    var itemProperties = rowData.GetType().GetTypeInfo().DeclaredProperties;

    var column = dataGrid.Columns[e.CurrentRowColumnIndex.ColumnIndex];

    string mappingName = column.MappingName;


    var pDesc = itemProperties.FirstOrDefault(p => p.Name == mappingName);

    if (pDesc != null)

        pDesc.SetValue(rowData,newitem);

}



UG Link:https://help.syncfusion.com/xamarin-android/sfdatagrid/editing#currentcellbeginedit

Please let us know if you have any concerns

Regards,

Suthi Yuvaraj.


Loader.
Live Chat Icon For mobile
Up arrow icon