Using CurrentCellEndEdit to modify contents of another cell

I have a need to trigger the change of multiple cells of the current row of a sfDataGrid with an ItemSource of a DataTable during the CurrentCellEndEdit event.

XAML:

            <syncfusion:SfDataGrid x:Name="sfdg1" Height="510" Width="1100" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.ColumnSpan="3" Grid.Row="2" Grid.RowSpan="3" Margin="4" EditTrigger="OnTap" GridValidationMode="InEdit" AddNewRowPosition="Bottom" LiveDataUpdateMode="Default"/>

<VB to build table and add as ItemSource>
    Private Sub CreateTable()
        TransferTable = New DataTable("Transfer")
        Dim NewColumn As New System.Data.DataColumn("KeyedLotNo", System.Type.GetType("System.String"))
        NewColumn.Unique = True
        TransferTable.Columns.Add(NewColumn)
        TransferTable.Columns.Add(New System.Data.DataColumn("PLUNo", System.Type.GetType("System.Int32")))
        TransferTable.Columns.Add(New System.Data.DataColumn("Description", System.Type.GetType("System.String")))
        TransferTable.Columns.Add(New System.Data.DataColumn("Source", System.Type.GetType("System.String")))
        TransferTable.Columns.Add(New System.Data.DataColumn("QtyAvail", System.Type.GetType("System.Int32")))
        TransferTable.Columns.Add(New System.Data.DataColumn("AvgWgt", System.Type.GetType("System.Decimal")))
        TransferTable.Columns.Add(New System.Data.DataColumn("Quantity", System.Type.GetType("System.Int32")))
        TransferTable.Columns.Add(New System.Data.DataColumn("Weight", System.Type.GetType("System.Decimal")))
        TransferTable.Columns.Add(New System.Data.DataColumn("NewOSLot", System.Type.GetType("System.String")))
        TransferTable.Columns.Add(New System.Data.DataColumn("NewAllensLot", System.Type.GetType("System.String")))
        sfdg1.LiveDataUpdateMode = Syncfusion.Data.LiveDataUpdateMode.AllowDataShaping
        sfdg1.AutoGenerateColumns = True
        sfdg1.AllowDraggingColumns = False
        sfdg1.AllowDraggingRows = False
        sfdg1.AllowSorting = False
        sfdg1.AllowGrouping = False
        sfdg1.ColumnSizer = GridLengthUnitType.AutoLastColumnFill
        sfdg1.ItemsSource = TransferTable
        sfdg1.Columns(0).HeaderText = "Lot No"
        sfdg1.Columns(0).MinimumWidth = 75
        sfdg1.Columns(0).AllowEditing = True
        sfdg1.Columns(0).CellStyle = TransparentStyle
        sfdg1.Columns(0).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(1).HeaderText = "PLU No"
        sfdg1.Columns(1).MinimumWidth = 75
        sfdg1.Columns(1).CellStyle = BlueStyle
        sfdg1.Columns(1).AllowEditing = False
        sfdg1.Columns(1).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(2).HeaderText = "Description"
        sfdg1.Columns(2).MinimumWidth = 200
        sfdg1.Columns(2).CellStyle = BlueStyle
        sfdg1.Columns(2).AllowEditing = False
        sfdg1.Columns(2).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(3).HeaderText = "Source"
        sfdg1.Columns(3).MinimumWidth = 75
        sfdg1.Columns(3).CellStyle = BlueStyle
        sfdg1.Columns(3).AllowEditing = False
        sfdg1.Columns(3).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(4).HeaderText = "Available"
        sfdg1.Columns(4).MinimumWidth = 100
        sfdg1.Columns(4).CellStyle = BlueStyle
        sfdg1.Columns(4).AllowEditing = False
        sfdg1.Columns(4).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(5).HeaderText = "Avg Wgt"
        sfdg1.Columns(5).MinimumWidth = 75
        sfdg1.Columns(5).CellStyle = BlueStyle
        sfdg1.Columns(5).AllowEditing = False
        sfdg1.Columns(5).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(6).HeaderText = "Quantity"
        sfdg1.Columns(6).MinimumWidth = 100
        sfdg1.Columns(6).CellStyle = TransparentStyle
        sfdg1.Columns(6).AllowEditing = True
        sfdg1.Columns(6).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(7).HeaderText = "Weight"
        sfdg1.Columns(7).MinimumWidth = 100
        sfdg1.Columns(7).CellStyle = TransparentStyle
        sfdg1.Columns(7).AllowEditing = True
        sfdg1.Columns(7).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(8).HeaderText = "New OS Lot"
        sfdg1.Columns(8).MinimumWidth = 100
        sfdg1.Columns(8).CellStyle = TransparentStyle
        sfdg1.Columns(8).AllowEditing = True
        sfdg1.Columns(8).UpdateTrigger = UpdateSourceTrigger.PropertyChanged

        sfdg1.Columns(9).HeaderText = "New Allen Lot"
        sfdg1.Columns(9).MinimumWidth = 100
        sfdg1.Columns(9).CellStyle = BlueStyle
        sfdg1.Columns(9).AllowEditing = False
    End Sub



<VB>
    Private Sub sfdg1_CurrentCellEndEdit(sender As Object, e As CurrentCellEndEditEventArgs) Handles sfdg1.CurrentCellEndEdit
        If e.RowColumnIndex.ColumnIndex = 0 Then
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(1) = 1
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(2) = "TWO"
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(3) = "THREE"
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(4) = 4
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(5) = 5
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(6) = 6
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(7) = 7
            sfdg1.ItemsSource.Rows(e.RowColumnIndex.RowIndex - 1).Item(8) = "EIGHT"
        End If
  End Sub

Updating the ItemsSource only appears to update the new cell that triggered the end of the previous cell.  

When the user presses TAB to leave cell 0 of the current row and Item(1)'s value shows up in the next cell, but not the following cells of that row.  The underlying ItemsSource values are changed, but are not reflected in the sfDataGrid.

Is there a solution to this issue to force a refresh of the datagrid's row?

Thanks

1 Reply

JG Jai Ganesh S Syncfusion Team April 2, 2018 04:51 PM UTC

Hi David, 
 
You can achieve your requirement to notify the data table changes in SfDataGrid by call the AcceptChanges() method in DataTable like below, 
 
private void AssociatedObject_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e) 
{ 
    var dataRow = (this.AssociatedObject.CurrentItem as DataRowView).Row; 
 
    if(e.RowColumnIndex.ColumnIndex==0) 
    { 
        dataRow["Name"] = "One"; 
        dataRow["Country"] = "Italy"; 
        dataRow["Price"] = "45"; 
 
        (this.AssociatedObject.DataContext as ViewModel).DataTableCollection.AcceptChanges(); 
    } 
} 
 
 
Regards, 
Jai Ganesh S

Loader.
Up arrow icon