<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> |
<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();
} |
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>
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?
|
|
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.
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
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