How to edit a cell value programmatically?
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()
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
Regards,
Vijayarasan S