I have a somewhat obscure issue that I am unable to find a solution to based on example code or existing documentation on the SfTextBoxExt of SfDataGrid controls.
I have a solution that requires a bulk input screen using the SfDataGrid with multiple nested SfTextBoxExt controls. Is there anyway to pass the PreviewTextInput to the SfTextBoxExt nested in the GridTemplateColumn?
Further, is it possible to paste values into the nested SfTextBoxExt control? The customer has both of these as requirements, and based on the currently available documentation and samples it appears that we cannot do either.
XAML:
<helpers:BaseContentDialog.Resources>
<DataTemplate x:Key="MaterialTypeSelectionTemplate">
<sfInput:SfTextBoxExt x:Name="MaterialTypes"
Style="{DynamicResource DefaultTextBox}"
Margin="0"
AutoCompleteMode="SuggestAppend"
AutoCompleteSource="{Binding MaterialSetup.Materials}"
SearchItemPath="Description"
SelectedItem="{Binding MaterialType, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
syncfusion:FocusManagerHelper.FocusedElement="True" />
</DataTemplate>
<DataTemplate x:Key="MaterialTypeDisplayTemplate">
<TextBlock Margin="8" Text="{Binding MaterialType.Description}" />
</DataTemplate>
</helpers:BaseContentDialog.Resources>
Here is my OnTextInput override:
protected override void OnTextInput(TextCompositionEventArgs e)
{
if (!SelectionController.CurrentCellManager.HasCurrentCell)
{
base.OnTextInput(e);
return;
}
var rowColumnIndex = SelectionController.CurrentCellManager.CurrentRowColumnIndex;
var row = this.ResolveToRowIndex(rowColumnIndex.RowIndex);
RowGenerator rowGenerator;
FieldInfo fieldInfo = typeof(SfDataGrid).GetField("RowGenerator", BindingFlags.NonPublic | BindingFlags.Instance);
rowGenerator = fieldInfo.GetValue(this) as RowGenerator;
var dataRow = rowGenerator.Items.FirstOrDefault(item => item.RowIndex == rowColumnIndex.RowIndex);
if (dataRow != null && dataRow is DataRow)
{
var dataColumn = dataRow.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == rowColumnIndex.ColumnIndex);
char text;
char.TryParse(e.Text, out text);
if (dataColumn != null && !(dataColumn.GridColumn is GridTemplateColumn) && !dataColumn.IsEditing && SelectionController.CurrentCellManager.BeginEdit())
dataColumn.Renderer.PreviewTextInput(e);
}
base.OnTextInput(e);
}