I have xamdatagrid and within this grid there is a column which is of type combobox. Now based upon certain condition when I change the selection of the comobobox a new record should get added within the Grid. Please suggest if I need to add trigger to the combobox upon selectionchanged and raise and event in that case I would need the index of currently grid row selected and index of combov=box selected item.
Please advise how can achive the above.
Below is the xaml code:
<UserControl x:Class="DLVR.IndividualPositionReport.Visualisation.Views.AggreagteCalcParamCollectionView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:DLVR.IndividualPositionReport.Visualisation.Views" xmlns:bmg="clr-namespace:DLVR.IndividualPositionReport.Visualisation.BenchmarkGrid" xmlns:bm="clr-namespace:DLVR.IndividualPositionReport.Visualisation.CompensationBlock" xmlns:vp="clr-namespace:DLVR.Shared.BaseClasses.VisualisationParameters;assembly=DLVR.Shared" xmlns:idp="http://infragistics.com/DataPresenter" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ig="http://infragistics.com/Editors" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="Auto"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Grid.Resources> <Style x:Key="textField" TargetType="{x:Type idp:CellValuePresenter}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ItemsControl ItemsSource="{Binding Path=DataContext.DataItem.Value.Parameters,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type idp:CellValuePresenter}}}" DataContext="{Binding Value,Mode=OneWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction CommandParameter="{Binding Path=DataContext.DataItem}" Command="{Binding DataContext.SelectChangeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type idp:CellValuePresenter}}}"/> </i:EventTrigger> </i:Interaction.Triggers> <ItemsControl.ItemTemplate> <DataTemplate> <ig:XamTextEditor Value="{Binding Value}"> <ig:XamTextEditor.Template> <ControlTemplate> <TextBlock Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></TextBlock> </ControlTemplate> </ig:XamTextEditor.Template> <ig:XamTextEditor.EditTemplate> <ControlTemplate> <TextBox Text="{Binding Value, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></TextBox> </ControlTemplate> </ig:XamTextEditor.EditTemplate> </ig:XamTextEditor> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel></StackPanel> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="combo" TargetType="{x:Type idp:CellValuePresenter}"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <ComboBox ItemsSource="{Binding Path=DataContext.DataItem.Options,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type idp:CellValuePresenter}}}" DisplayMemberPath="Label" SelectedItem="{Binding Path=DataContext.DataItem.Value,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type idp:CellValuePresenter}}}"> </ComboBox> </DataTemplate> </Setter.Value> </Setter> </Style> </Grid.Resources> <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center"> <Button Content="Add Row" Width="100" Margin="0,0,20,0" Command="{Binding AddNewRowCommand}"></Button> <Button Content="Delete Row(s)" Width="100" Command="{Binding DeleteRowCommand}"></Button> </StackPanel> <StackPanel Orientation="Horizontal" Grid.Row="1"> <CheckBox IsChecked="{Binding IsVarianceChecked}" Width="Auto" Command="{Binding VarianceCommand}"/> <TextBlock Text="Show variance from Sponsor" Width="Auto"/> </StackPanel> <idp:XamDataGrid x:Name="td" Grid.Row="2" DataSource="{Binding FilteredCalcParameter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedDataItems="{Binding SelectedRows,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" SelectedDataItemsScope="RecordsOnly" IsSynchronizedWithCurrentItem="True"> <idp:XamDataGrid.FieldLayoutSettings> <idp:FieldLayoutSettings AutoGenerateFields="False" ></idp:FieldLayoutSettings> </idp:XamDataGrid.FieldLayoutSettings> <idp:XamDataGrid.FieldLayouts> <idp:FieldLayout> <idp:FieldLayout.Fields> <idp:UnboundField BindingPath="Value" Label="Calculation" CellValuePresenterStyle="{StaticResource ResourceKey=combo}"> </idp:UnboundField> <idp:UnboundField BindingPath="Value" Label="Parameter (where applicable)" BindingMode="TwoWay" CellValuePresenterStyle="{StaticResource ResourceKey=textField}"> </idp:UnboundField> </idp:FieldLayout.Fields> </idp:FieldLayout> </idp:XamDataGrid.FieldLayouts> </idp:XamDataGrid> </Grid></UserControl>
Hello Richa,
I have answered this question on the following forum thread:
https://es.infragistics.com/community/forums/t/111294.aspx
Let me know if you have any questions.
Sincerely,ZhivkoAssociate Software Developer