We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PreviewTextInput on SfDataGrid:GridTemplateColumn

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);
        }

1 Reply

GM Gobikrishnan Murugesan Syncfusion Team January 17, 2017 03:26 AM UTC

Hi Brandon, 
We have checked your provided code snippet (Datatemplate definition and OnTextInput override method). Based on our understanding we have created sample for your requirement. If your requirement is different from us then could you please provide more information about your query like explaining about the exact requirement or modify below sample and replication steps to reproduce the requirement? It would help us to proceed further. 
Regards, 
Gobikrishnan 


Loader.
Up arrow icon