How to edit a cell value programmatically?

This is my first post. I can't seem to figure this out.

My grid is populated using EF query.
Part of the functionality of this app requires me to change values in cells of a given row based on user action. I don't want to reload the grid by refreshing the datasource because the grid may contain hundreds, if not thousands, of rows. I don't want to round-trip to the DB just to change the data in a single cell.

I am new to data grids in general, in the past I've used listview because it's so much simpler.. 

Anyway, I have tried a few things:

DrugGrid.AllowEditing = true;

RowColumnIndex rowColumnIndex = new RowColumnIndex(DrugGrid.SelectedIndex, 7);

DrugGrid.MoveToCurrentCell(rowColumnIndex);

Syncfusion.WinForms.DataGrid.Interactivity.CurrentCellManager cc = DrugGrid.CurrentCell;

cc.BeginEdit();

cc.CellRenderer.SetControlValue("Test"); // emits "value cannot be set for an unloaded editor"

cc.EndEdit();


and this:


Syncfusion.Data.RecordEntry record = DrugGrid.View.GetRecordAt(DrugGrid.SelectedIndex);      

record.Data.GetType().GetProperty("GPackSize").SetValue(record.Data, "Test"); // emits "Property set method not found" but looks fine in intellisense.. so runtime.. 


DrugGrid.View.CommitEdit();



I understand that essentially you need to set the row and column of the cell you want to edit, move to that cell, enter editing mode, make the edit, end the editing move and commit the change.


That is a LOT of work to change A to B, but, that aside, I am only stuck at the data entry part. 


Can anyone clue me in here?


Thanks 


edit: I also tried this


var record = DrugGrid.View.Records.GetItemAt(DrugGrid.SelectedIndex); // OK

var changed = DrugGrid.View.GetPropertyAccessProvider().SetValue(record, "GPackSize", "Hello"); // returns true, suggesting "record" was updated

System.Diagnostics.Debug.WriteLineIf(changed, "Value was changed"); // as expected

System.Diagnostics.Debug.WriteLine(record.GetType().GetProperty("GPackSize").GetValue(record, null).ToString()); // writes the OLD value


Do I have to commit changes? 


I have also tried View.Refresh() and Grid.Refresh()





1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team March 16, 2021 04:01 PM UTC

Hi Bob,

Thank you for contacting Syncfusion support.

We have prepared a simple sample to programmatically change the value of a cell using the code snippets you have provided. But unfortunately we are unable to reproduce the reported problem. The value is changed properly. The sample we have used to check this is available in the following link for you reference.

Sample link: https://www.syncfusion.com/downloads/support/forum/163536/ze/SfDataGrid_Demo-1810699456
 
We suspect that the occurrence of the reported problem may depends on the type of the DataSource collection used for the SfDataGrid. Please revert to us with details about the DataSource used in your application. Or try to reproduce the reported issue in the above given sample and revert to us with the modified sample. It will be more helpful for us to find the exact cause for the problem and to provide a prompt solution at earlier.
  

Regards,
Vijayarasan S
 


Marked as answer
Loader.
Up arrow icon