Reputation: 737
I have a GridView that is bound to data using MVVM.
I want the users to be able to select an available description from a list or write a text.
I also want the Description list to change based on the values in SL column.
Here is my code:
<telerik:GridViewDataColumn Header="Description" Width="180">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description1}"/>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadComboBox IsEditable="True" ItemsSource="{Binding SLStandardDescriptions}"
Text="{Binding Description1,Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="DropDownOpened">
<i:InvokeCommandAction Command="{Binding DataContext.SLStandardDescriptionsDropDownOpenedCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
and in ViewModel:
private async void OnSLStandardDescriptionsDropDownOpened()
{
if (AccDocumentItem?.SL != null)
{
AccDocumentItem.SLStandardDescriptions = await _uow.SLStandardDescriptions.Where(x => x.SLId == AccDocumentItem.SLId).Select(x=>x.SLStandardDescriptionTitle).ToListAsync();
}
}
Upvotes: 1
Views: 281
Reputation: 4096
Try using this:
<telerik:GridViewDataColumn Header="Description" Width="180">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<telerik:RadComboBox IsEditable="True"
ItemsSource="{Binding SLStandardDescriptions}"
Text="{Binding Description1,Mode=TwoWay}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="DropDownOpened">
<i:InvokeCommandAction Command="{Binding DataContext.SLStandardDescriptionsDropDownOpenedCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
Upvotes: 1