Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
320
How to trigger combo box field selection changed event in xamdatagrid and set value to combo box field based on another selected item from different combo box.
posted

I have a xamdatagrid. I have added 2 combo box fields in xamdatagrid.

The item source for 2nd combo box should be set based on 1st combo box selection.

In the below example, I need to show books based on branch selection from branch combo box field.

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <ig:XamDataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                        GroupByAreaLocation="None"                                
                        DataSource="{Binding Employees, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, Mode=TwoWay}"
                        BorderBrush="Black" BorderThickness="0.5"
                        AutoFit="True">

            <ig:XamDataGrid.FieldSettings>
                <ig:FieldSettings AllowRecordFiltering="True" />
            </ig:XamDataGrid.FieldSettings>

            <ig:XamDataGrid.FieldLayoutSettings>
                <ig:FieldLayoutSettings HighlightAlternateRecords="True"
                                        AutoGenerateFields="False"
                                        AutoFitMode="ExtendLastField" />
            </ig:XamDataGrid.FieldLayoutSettings>

            <ig:XamDataGrid.FieldLayouts>
                <ig:FieldLayout>
                    <ig:Field Name="Name" Label="Default Name" Width="InitialAuto">
                        <ig:Field.Settings>
                            <ig:FieldSettings  AllowEdit="False"/>
                        </ig:Field.Settings>
                    </ig:Field>

                    <ig:ComboBoxField Name="Branches" Label="Branch" BindingType="Unbound" >

                        <ig:Field.Settings>
                            <ig:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" >
                                <ig:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <Setter Property="ItemsSource" 
                                                Value="{Binding Path=DataContext.Branches, RelativeSource={RelativeSource AncestorType={x:Type ig:XamDataGrid}} ,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                                        <Setter Property="DisplayMemberPath" Value="Name">

                                       </Setter>

                                        <Setter Property="SelectedItem" Value="{Binding DataItem.SelectedBranch}">

                                        </Setter>

                                    </Style>
                                </ig:FieldSettings.EditorStyle>
                            </ig:FieldSettings>
                        </ig:Field.Settings>

                    </ig:ComboBoxField>

                    <ig:ComboBoxField Name="Books" Label="Book" BindingType="Unbound" >

                        <ig:Field.Settings>
                            <ig:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" >
                                <ig:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <Setter Property="ItemsSource" 
                                                Value="{Binding Path=DataContext.Books, RelativeSource={RelativeSource AncestorType={x:Type ig:XamDataGrid}} ,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                                        <Setter Property="DisplayMemberPath" Value="Name">

                                        </Setter>

                                        <Setter Property="SelectedItem" Value="{Binding DataItem.SelectedBook}">

                                        </Setter>

                                    </Style>
                                </ig:FieldSettings.EditorStyle>
                            </ig:FieldSettings>
                        </ig:Field.Settings>

                    </ig:ComboBoxField>

                </ig:FieldLayout>
            </ig:XamDataGrid.FieldLayouts>

        </ig:XamDataGrid>
                                   


    </Grid>

Sample proj

WpfApp3.zip