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

CellValueChanged Event

Hi All,

I am new to Syncfusion. Please let me know the equivalent event of CellValueChanged of datagridview in Syncfusion SfDatagrid. I want to achieve the below code for sfDatagrid. The below code is of Winforms Datagridview CellValueChanged  event. I want to do the same thing with sfDatagrid

Private Sub gvItems_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gvItems.CellValueChanged
        Try
            If isSearch = True Then
                Exit Sub
            End If

            If gvItems.Rows.Count = 0 Then
                Exit Sub
            End If
            If e.ColumnIndex = 0 Then
                If IsNothing(gvItems.CurrentRow.Cells("AbhishekNo").Value) = True Then
                    Exit Sub
                End If
                Dim dt As New DataTable
                dt = objCommonMethods.GetDevkrityaDetailsByNo(SqlCon, gvItems.CurrentRow.Cells("AbhishekNo").Value)
                If dt.Rows.Count > 0 Then

                    gvItems.CurrentRow.Cells("AbhishekNo").Value = dt.Rows(0)("AbhishekNo").ToString()
                    gvItems.CurrentRow.Cells("AbhishekType").Value = Convert.ToInt32(dt.Rows(0)("AbhishekTypeId"))
                    gvItems.CurrentRow.Cells("ItemCode").Value = dt.Rows(0)("InternalId")
                    gvItems.CurrentRow.Cells("PoojaName").Value = dt.Rows(0)("InternalId")
                    gvItems.CurrentRow.Cells("Quantity").Value = "1"
                    gvItems.CurrentRow.Cells("Rate").Value = dt.Rows(0)("AbhishekAmt").ToString()
                    'gvItems.CurrentRow.Cells("TotalAmt").Value = dt.Rows(0)("AbhishekAmt").ToString()
                End If
                gvItems.Rows.Add("")
            End If
            If e.ColumnIndex = 1 Then
                If IsNothing(gvItems.CurrentRow.Cells("PoojaName").Value) = True Then
                    Exit Sub
                End If
                Dim dt As New DataTable
                dt = objCommonMethods.GetPoojaNameDetails(SqlCon, gvItems.CurrentRow.Cells("PoojaName").Value)
                If dt.Rows.Count > 0 Then

                    gvItems.CurrentRow.Cells("AbhishekNo").Value = dt.Rows(0)("AbhishekNo").ToString()
                    gvItems.CurrentRow.Cells("AbhishekType").Value = Convert.ToInt32(dt.Rows(0)("AbhishekTypeId"))
                    gvItems.CurrentRow.Cells("ItemCode").Value = dt.Rows(0)("InternalId")
                    'gvItems.CurrentRow.Cells("PoojaName").Value = dt.Rows(0)("InternalId")
                    gvItems.CurrentRow.Cells("Quantity").Value = "1"
                    gvItems.CurrentRow.Cells("Rate").Value = dt.Rows(0)("AbhishekAmt").ToString()
                    'gvItems.CurrentRow.Cells("TotalAmt").Value = dt.Rows(0)("AbhishekAmt").ToString()
                End If
                'gvItems.Rows.Add("")
            End If
            If e.ColumnIndex = 2 Then
                If IsNothing(gvItems.CurrentRow.Cells("ItemCode").Value) = True Then
                    Exit Sub
                End If
                Dim dt As New DataTable
                dt = objCommonMethods.GetPoojaNameDetails(SqlCon, gvItems.CurrentRow.Cells("ItemCode").Value)
                If dt.Rows.Count > 0 Then
                    'gvItems.CurrentRow.Cells("TotalAmt").Value = dt.Rows(0)("AbhishekAmt").ToString()
                    gvItems.CurrentRow.Cells("AbhishekNo").Value = dt.Rows(0)("AbhishekNo").ToString()
                    gvItems.CurrentRow.Cells("AbhishekType").Value = Convert.ToInt32(dt.Rows(0)("AbhishekTypeId"))
                    gvItems.CurrentRow.Cells("PoojaName").Value = dt.Rows(0)("InternalId")
                    gvItems.CurrentRow.Cells("Quantity").Value = "1"
                    gvItems.CurrentRow.Cells("Rate").Value = dt.Rows(0)("AbhishekAmt").ToString()
                End If
                'gvItems.Rows.Add("")
            End If
            If e.ColumnIndex = 2 Then
                If IsNothing(gvItems.CurrentRow.Cells("ItemCode").Value) = True Then
                    Exit Sub
                End If
                Dim dt As New DataTable
                dt = objCommonMethods.GetPoojaNameDetails(SqlCon, gvItems.CurrentRow.Cells("ItemCode").Value)
                If dt.Rows.Count > 0 Then
                    'gvItems.CurrentRow.Cells("TotalAmt").Value = dt.Rows(0)("AbhishekAmt").ToString()
                    gvItems.CurrentRow.Cells("AbhishekNo").Value = dt.Rows(0)("AbhishekNo").ToString()
                    gvItems.CurrentRow.Cells("AbhishekType").Value = Convert.ToInt32(dt.Rows(0)("AbhishekTypeId"))
                    gvItems.CurrentRow.Cells("PoojaName").Value = dt.Rows(0)("InternalId")
                    gvItems.CurrentRow.Cells("Quantity").Value = "1"
                    gvItems.CurrentRow.Cells("Rate").Value = dt.Rows(0)("AbhishekAmt").ToString()
                End If
                'gvItems.Rows.Add("")
            End If
            If e.ColumnIndex = 0 Or e.ColumnIndex = 1 Or e.ColumnIndex = 2 Or e.ColumnIndex = 3 Or e.ColumnIndex = 4 Then
                CalculateDocumentTotal()
            End If
        Catch ex As Exception

        End Try
    End Sub

4 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team February 26, 2019 12:58 PM UTC

Hi Noor Hussain, 
 
Thanks for using Syncfusion product. 
 
You can able to achieve your requirement by using the CurrentCellEndEdit in SfDataGrid control. Please find the code snippet below, 
 
sfDataGrid1.CurrentCellEndEdit += sfDataGrid1_CurrentCellEndEdit; 
 
void sfDataGrid1_CurrentCellEndEdit(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellEndEditEventArgs e) 
{ 
    int rowIndex = e.DataRow.RowIndex; 
    int columnIndex = e.DataColumn.ColumnIndex; 
 
    // Implement your code based on the rowIndex and ColumnIndex values. 
} 
 
You can refer the below documentation for your reference, 
 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 



NH Noor Hussain March 2, 2019 05:07 AM UTC

Hello Jagadeesan - Apologies for the delayed response. Thanks a lot for the solution. But please let me know if it is mandatory to bind the sfDatagrid with datasource ? Or can I set the values of the cells manually  ? like I am doing below in windows datagridview.

Public Sub FillChildData(ByVal dt As DataTable)
        If gvItems.RowCount > 0 Then
            gvItems.Rows.Clear()
        End If
        For i As Integer = 0 To dt.Rows.Count - 1
            gvItems.Rows.AddNew()
            gvItems.Rows(i).Cells("PoojaName").Value = dt.Rows(i)("AbhishekId")
            gvItems.Rows(i).Cells("AbhishekNo").Value = dt.Rows(i)("AbhishekNo").ToString
            gvItems.Rows(i).Cells("TotalAmt").Value = dt.Rows(i)("AbhishekAmt").ToString
            gvItems.Rows(i).Cells("AbhishekType").Value = Convert.ToInt32(dt.Rows(i)("AbhishekTypeId"))
            gvItems.Rows(i).Cells("Quantity").Value = dt.Rows(0)("Quantity").ToString()
            gvItems.Rows(i).Cells("Rate").Value = dt.Rows(0)("Rate").ToString()
        Next


    End Sub

I want to add the rows manually and set the cell values by looping through the datasource.

Regards,
Noor


MA Mohanram Anbukkarasu Syncfusion Team March 4, 2019 01:13 PM UTC

Hi Noor Hussain,

Thanks for your update.

SfDataGrid is data bound control designed to display the bounded data in a tabular format. It is not possible to set the values for the cells manually since it is not a cell based control. Please refer the following link.



It is possible to add rows and columns without binding any DataSource by using the UnboundRows and UnboundColumns support in SfDataGrid. Please refer the following UG documentations.

UG links 


Please let us know if you need futher assistance in this.

Regards,
Mohanram A.



JO Josiah July 6, 2022 07:56 AM UTC

Thank you for making this decision.

slope game


End If

gvItems.Rows.Add("")

End If

If e.ColumnIndex = 1 Then

If IsNothing(gvItems.CurrentRow.Cells("PoojaName").Value) = True Then

Exit Sub

End If

Dim dt As New DataTable

dt = objCommonMethods.GetPoojaNameDetails(SqlCon, gvItems.CurrentRow.Cells("PoojaName").Value)

If dt.Rows.Count > 0 Then



Loader.
Live Chat Icon For mobile
Up arrow icon