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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Current Row

Thread ID:

Created:

Updated:

Platform:

Replies:

148297 Oct 14,2019 01:42 PM UTC Oct 15,2019 12:37 PM UTC WinForms 1
loading
Tags: SfDataGrid
Tiago
Asked On October 14, 2019 01:42 PM UTC

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

Gowtham Gopalsamy [Syncfusion]
Replied On 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      


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon