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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CellValueChanged Event

Thread ID:

Created:

Updated:

Platform:

Replies:

142936 Feb 26,2019 11:54 AM UTC Mar 4,2019 01:13 PM UTC WinForms 3
loading
Tags: SfDataGrid
Noor Hussain
Asked On February 26, 2019 11:54 AM UTC

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

Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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 


Noor Hussain
Replied On 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

Mohanram Anbukkarasu [Syncfusion]
Replied On 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.


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

;