Hello everybody,
I'm using SfDataGrid with three columns. There is a workflow implemented in which the user gets led through every column. After the user completed the column, the next one is focused. One of the columns is a GridDataTimeColumn so when it's automatically focused the datepicker opens. Everything fine!
However, the date is optional. In fact, the viewmodel's field is a nullable date. So if the user hits the cancel button, it would be nice to receive a null value.
The automation is picked from an older thread, it uses sfgrid_BeginEdit to bind completion events to every column:
private async void sfgrid_CurrentCellBeginEdit(object sender, GridCurrentCellBeginEditEventArgs args)
{
try
{
var row = sfgrid.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);
var content = ((column as IElement).Element as ContentView).Content;
if (content is Entry && !_entryCompletedLotAdded)
{
(content as Entry).Completed += Charge_Completed;
_entryCompletedLotAdded = true;
}
else if (content is SfNumericTextBoxExt && !_entryNumericCompletedAdded)
{
(content as SfNumericTextBoxExt).Completed += Gewaehlt_Completed;
_entryNumericCompletedAdded = true;
}
else if (content is SfDatePicker && !_dateSelectedAdded)
{
(content as SfDatePicker).Unfocused += Mhd_Unfocused;
_dateSelectedAdded = true;
}
}
catch (Exception ex)
{
await Application.Current.MainPage.DisplayAlert(Translator.Translate("Fehler"), ex.Message, "OK");
}
}
It uses SfDataPicker.Unfocused because DateSelected didn't work if the user just pressed the ok button without making any changes inside the date picker.
Hope you can help :)