Adding new row: how to update other cell values without leaving current cell?

Hi,

SfDataGrid has GridComboBoxColumn, DisplayMember is car number. When adding a new row, user selects a car number in the ComboBox column. Columns like "car model" are read only for information purposes. 

How to change the contents of these read only information cells, as user is selecting different cars? When updating the current Record in CellComboBoxSelectionChanged, values are displayed only when combo box cell has lost focus.

 private void grid_CellComboBoxSelectionChanged(object sender, CellComboBoxSelectionChangedEventArgs e)
{
if (e.GridColumn.MappingName == "car")
{
var car = e.SelectedItem as Car;
var row = e.Record as Dto;
row.Model = car.ModelName;   // Grid should display this value right away
row.Company = car.Company.ShortName; // Grid should display this value right away
}
}


3 Replies

MA Mohanram Anbukkarasu Syncfusion Team July 27, 2018 12:46 PM UTC

Hi Tipal, 

Thanks for contacting Syncfusion support. 

By default, changes made in the current record of the record cells will be immediately reflected in the view, if the underlying DataSource is implemented with the INotifyPropertyChanged interface. But the changes made in the AddNewRow record will not be reflected immediately in the view. To achieve this requirement, the AddNewRow should be invalidated after updating the current record in the CellComboBoxSelectionChanged event.  

Please refer to the below code example and sample from the given location. 

Code Example: 
this.sfDataGrid1.CellComboBoxSelectionChanged += sfDataGrid1_CellComboBoxSelectionChanged; 
 
void sfDataGrid1_CellComboBoxSelectionChanged(object sender, CellComboBoxSelectionChangedEventArgs e) 
{ 
    if (e.GridColumn.MappingName == "ShipCityID") 
    { 
        var shipCityDetails = e.SelectedItem as ShipCityDetails; 
        var row = e.Record as OrderInfo; 
        row.OrderID = shipCityDetails.ShipCityID; 
        if (e.RowIndex == this.sfDataGrid1.GetAddNewRowIndex()) 
            this.sfDataGrid1.TableControl.Invalidate(this.sfDataGrid1.TableControl.GetRowRectangle(this.sfDataGrid1.GetAddNewRowIndex(), false)); 
    } 
} 


Regards, 
Mohanram A. 




T T July 27, 2018 01:33 PM UTC

Most helpful, thank you very much!


MA Mohanram Anbukkarasu Syncfusion Team July 30, 2018 05:41 AM UTC

Hi Tipal,  

Thanks for your update. 

We are glad to know that the given solution has resolved your query. Please let us know, If you need any further assistance. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon