Syncfusion SfDataGrid のセル編集をキーボードの改行(Enter/Return キー)で編集を確定する方法です。
※ この記事の投稿時点の SfDataGrid のバージョンは v15.2.0.46 です。
Editing 機能で Excel のセルのように編集できます。改行をハンドリングするには、CurrentCellBeginEdit
イベントで処理します。
// _dataGrid: SfDataGrid
_dataGrid.CurrentCellBeginEdit += DataGrid_CurrentCellBeginEdit;
private async void DataGrid_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs args) { await Task.Delay(100); if (!(args.Column is GridTextColumn)) return; var row = _dataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == args.RowColumnIndex.RowIndex); var column = (row.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "VisibleColumns").GetValue(row) as List<DataColumnBase>).FirstOrDefault(x => x.ColumnIndex == args.RowColumnIndex.ColumnIndex) as IElement; if (column.Element.Subviews.Length > 0) { if (column.Element.Subviews[0] is UITextField) { ((UITextField)column.Element.Subviews[0]).ShouldReturn = textField => { _dataGrid.EndEdit(); // 編集終了 return true; }; } } }