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

Current Row

Hello 
Previously when using Visual Studio native control the DataGridView, to get the value of a cell in the current line used the following code:

DatagridView1.CurrentRow.Cells [2] .Value.ToString ()

What code do I use for the sfDataGrid1 control?

Best Regards

Tiago Marques
Portugal

1 Reply

GG Gowtham Gopalsamy Syncfusion Team October 15, 2019 12:37 PM UTC

Hi Tiago,    
    
Thank you for using Syncfusion controls.     
   
SfDataGrid is data bounded. So, SfDataGrid doesn’t have the support to get the cell value as like as DataGridView by using Row and Column index. You can achieve your requirement to get the cell value in SfDataGrid as like as DataGridView by using the DataGridHelper class GetCellValue method.   
   
Please refer the below code snippet.  
    
private void button1_Click(object sender, EventArgs e)   
{   
    if (this.sfDataGrid.SelectionController.DataGrid.CurrentCell.ColumnIndex != -1 &&this.sfDataGrid.SelectionController.DataGrid.CurrentCell.RowIndex != -1)   
    {   
        var rowIndex = this.sfDataGrid.SelectionController.DataGrid.CurrentCell.RowIndex;   
        var recordIndex = sfDataGrid.TableControl.ResolveToRecordIndex(rowIndex);   
   
        var cellValue = DataGridHelper.GetCellValue(this.sfDataGrid, recordIndex, 2);   
        MessageBox.Show("Value in cell  " + cellValue.ToString());   
    }   
}   
   
   
public static class DataGridHelper   
{   
    public static object GetCellValue(SfDataGrid sfDataGrid, int recordIndex, intcolumnindex)   
    {   
        object cellValue = null;   
   
        var record1 = sfDataGrid.View.Records.GetItemAt(recordIndex);   
        var mappingName = sfDataGrid.Columns[columnindex].MappingName;   
        cellValue = record1.GetType().GetProperty(mappingName).GetValue(record1, null);   
        if (cellValue != null)   
        {   
            return cellValue;   
        }   
        return null;   
    }   
}   
   
Please refer the below sample link.  
   
   
Please refer the below UG link.   
   
   
Please let us know, If you require further assistance on this.   
   
Regards,       
Gowtham      


Loader.
Live Chat Icon For mobile
Up arrow icon