SfTextBoxExt selection not working in SfDataGrid

am using SfTextBoxExt in a GridTemplateColumn along with a GridSelectionController that handles moving to the next cell by using enter key press

the contradiction happens when am in the SfTextBoxExt cell and i select something from the drop down list, what should happen is an item should be selected but instead nothing gets selected and i just get moved to the next cell

i should note that if i select using the mouse the selection works fine

what can i do to resolve this contradiction? isn't there another way of navigating the SfDataGrid without using a GridSelectionController?

PS: i attached a sample to illustrate the issue.

Edit: i just found out that the problem acquires even without the GridSelectionController.

Attachment: SampleApp_1ef4c4a1.rar


8 Replies

VS Vijayarasan Sivanandham Syncfusion Team May 14, 2020 03:41 AM UTC

Hi Joseph,

Thank you for contacting Syncfusion support.

Currently, we are analyzing your requirement of “SfTextBoxExt Selection not working in SfDataGrid”. We will validate and update you the details on May 15, 2020.
 
 
We appreciate your patience until then. 
 
Regards, 
Vijayarasan S 



VS Vijayarasan Sivanandham Syncfusion Team May 15, 2020 04:53 PM UTC

Hi Joseph

Thank you for your patience,

Your requirement can be achieved by use the Text property in GridTemmplateColumn. EditTemplate. Please refer the below code snippet,
 
<sf:GridTemplateColumn.EditTemplate> 
       <DataTemplate> 
             <sf:SfTextBoxExt 
                     SearchItemPath="Name" 
                     AutoCompleteMode="Suggest" 
                     Text="{Binding Product.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                     SuggestionMode="Contains" 
                     ShowSuggestionsOnFocus="False" 
                      sf:FocusManagerHelper.FocusedElement="True" 
                      PreviewTextInput="SfTextBoxExt_PreviewTextInput" 
                      VerticalContentAlignment="Center"> 
            </sf:SfTextBoxExt> 
        </DataTemplate> 
</sf:GridTemplateColumn.EditTemplate> 
 
We hope this helps. Please let us know, if you require further assistance on this. 
Regards,
Vijayarasan S 



JO Joseph May 15, 2020 08:42 PM UTC

am sorry to report this but what you proposed still doesn't solve my problem, i need to use either the SelectedItem or SelectedValue properties to push the selected item (product) to the bound orderline.

binding to the text property alone isn't enough because now the selection happens only on the UI and nothing gets selected on actual bound orderline.

what should i do now...because i really wanna use this control and not any other because it's filled with functionality that i would like to use!


VS Vijayarasan Sivanandham Syncfusion Team May 18, 2020 05:20 PM UTC

Hi Joseph, 
Thanks for the update. 
Your requirement can be achieved using SelectedItemChanged event in SfTextBoxExt. Please refer the below codesnippet, 
<sf:GridTemplateColumn.EditTemplate> 
          <DataTemplate> 
                <sf:SfTextBoxExt 
                        SearchItemPath="Name"  
                        AutoCompleteMode="Suggest"                                      
                        Text="{Binding Product.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"                              
                        SuggestionMode="Contains"  
                        ShowSuggestionsOnFocus="False" 
                        SelectedItemChanged="SfTextBoxExt_SelectedItemChanged" 
                        sf:FocusManagerHelper.FocusedElement="True"  
                        PreviewTextInput="SfTextBoxExt_PreviewTextInput"                                                                     
                        VerticalContentAlignment="Center"> 
               </sf:SfTextBoxExt> 
          </DataTemplate> 
</sf:GridTemplateColumn.EditTemplate> 
 
private void SfTextBoxExt_SelectedItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
{ 
            var SelectedVallue = (e.NewValue as Product).Name.ToString();            
            
} 
 
Regards,
Vijayarasan S
 



NV NM van Strien September 8, 2022 09:30 PM UTC

Hi -


I am facing a similar problem as described in this forum post. I find the sample interesting, but I am trying to use MVVM.


I am trying to set the AutoCompleteSource in xaml directly, and  I am sure the MedicationDBItemsSource is properly bound and populated (on the ViewModel).


I am also using a pager on the datagrid. Is that a problem perhaps?


Is there perhaps an MVVM style sample of the use of SfTextboxExt in SfDataGrid?


Kind regards,


Niels van Strien


<sf:GridTemplateColumn.EditTemplate>
                        <DataTemplate>
                            <sf:SfTextBoxExt
                                x:Name="ProductNameTBControl"
                                SearchItemPath="ProductName"
                                AutoCompleteMode="Suggest"
                                AutoCompleteSource="{Binding MedicationDBItemsSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                SelectedItem="{Binding SelectedMed, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                Text="{Binding MedCBGProductName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                SuggestionMode="ContainsOrdinal"
                                HighlightedTextColor="#FFD65532"
                                TextHighlightMode="MultipleOccurrence"
                                IsEnabled="True">
                            </sf:SfTextBoxExt>
                        </DataTemplate>
                    </sf:GridTemplateColumn.EditTemplate>


VS Vijayarasan Sivanandham Syncfusion Team September 9, 2022 07:36 PM UTC

Hi Niels van Strien,

Please find answer for your queries below

Queries

Solutions

 

I am also using a pager on the datagrid. Is that a problem perhaps?

 

 

No, the reported issue does not occur because of SfDataPager.

 

Is there perhaps an MVVM style sample of the use of SfTextboxExt in SfDataGrid?

 


We have prepared the sample to meet your requirement. Please find the sample in the attachment.


Please have a look at this sample and let us know if you have any concerns in this.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



Attachment: SfDataGridDemo_a688956.zip


NV NM van Strien September 10, 2022 09:52 AM UTC

Dear Vijayarasan,


Thank you - this was a really helpful MVVM example. I recommend adding it to the user documentation for wpf sfdatagrid  as an example of a template column with sftextboxex and autocomplete.


My code is now working - for completeness and in case other look through the forum:


The key part that missed in my original code was


xaml in the definition of the SfTextboxExt (i.e. before </sf:SfTextBoxExt>):

<i:Interaction.Triggers>
                                    <i:EventTrigger EventName="PreviewTextInput">
                                        <i:InvokeCommandAction
                                            Command="{Binding Path=PreviewTextInputCommand,ElementName=MainDataGrid}"
                                            PassEventArgsToCommand="True"
                                            />
                                    </i:EventTrigger>
  </i:Interaction.Triggers>


and on the viewmodel I added


in the constructor:

PreviewTextInputCommand = new DelegateCommand<TextCompositionEventArgs>(PreviewTextInputExecute);


And these two methods:

private async void PreviewTextInputExecute(TextCompositionEventArgs p)
        {
            if (p.OriginalSource is SfTextBoxExt tb)
            {
                MedProductNameTBControl = tb;
            }


            var filter = p.Text.Trim();


            if (!string.IsNullOrEmpty(filter))
            {
                var suggestionlist = await GetSuggestionsByFilter(filter);
                MedicationDBItemsSource = new ObservableCollection<CBGMedicationModel>(suggestionlist);
            }
        }


        private async Task<List<CBGMedicationModel>> GetSuggestionsByFilter(string filter)
        {
            List<CBGMedicationModel>? output;


            if (UIItemsSources.MedicationDBItemsSourceCache != null)
            {
                output = UIItemsSources.MedicationDBItemsSourceCache.Where(x => x.ProductName.ToLower().Contains(filter.ToLower())).ToList();


                if (output != null && output.Any())
                {
                    return output;
                }
                else
                {
                    return new List<CBGMedicationModel>();
                }
            }
            else
            {
                await LoadItemsSourcesForPrescriptionMedicationDesigner(new CancellationToken());
                return UIItemsSources.MedicationDBItemsSourceCache!.ToList();
            }
        }

Thank you so much for your help!


Kind regards,

Niels van Strien




VS Vijayarasan Sivanandham Syncfusion Team September 12, 2022 07:12 AM UTC

Hi Niels van Strien,

We have considered your suggestion. If you are satisfied with our response, please mark it as an answer. Otherwise, please let us know if you have any further queries on this. We are happy to help you😊.


Regards,

Vijayarasan S



Loader.
Up arrow icon