How to set the set the value of a control based on the value of another within a GridTemplateColumn

I am trying to set the value of a numeric up down control based on the value of a picker. I would like to set the value of the numeric up down after the selected item in the picker is changed. How can I achieve this?

Thank you in advance.

<forms:Grid x:Name="grid" VerticalOptions="FillAndExpand">

    <datagrid:SfDataGrid x:Name="dataGrid"

                            AutoGenerateColumns="False"

                            AllowPullToRefresh="True"

                            ColumnSizer="LastColumnFill"

                            ItemsSource="{Binding Products}"

                            RowHeight="150"

                            VerticalOptions="FillAndExpand">


        <datagrid:SfDataGrid.Columns>

            <datagrid:GridTemplateColumn HeaderCellTextSize="16"

                                            HeaderFontAttribute="Bold"

                                            HeaderText="Products"

                                            LineBreakMode="TailTruncation"

                                            MappingName="Id">


                <datagrid:GridTemplateColumn.CellTemplate>

                    <DataTemplate>

                        <Grid ColumnSpacing="0" RowSpacing="0">

                            <Grid.RowDefinitions>

                                <RowDefinition Height="*"/>

                            </Grid.RowDefinitions>


                            <Grid x:Name="productGrid"

                                    Grid.Row="0"

                                    Grid.Column="0"

                                    RowSpacing="0"

                                    Padding="5"

                                    BackgroundColor="Transparent">


                                <Grid.RowDefinitions>

                                    <RowDefinition Height="auto" />

                                </Grid.RowDefinitions>


                                <Grid.ColumnDefinitions>

                                    <ColumnDefinition Width="*" />

                                </Grid.ColumnDefinitions>


                                <Label x:Name="descriptionLabel"

                                        FontAttributes="Bold"

                                        FontSize="16"

                                        Grid.Row="0"

                                        Grid.Column="0"

                                        Grid.ColumnSpan="2"

                                        LineBreakMode="TailTruncation"

                                        Text="{Binding Description}"

                                        TextColor="Black"

                                        BackgroundColor="Transparent">

                                </Label>


                                <Picker x:Name="variationPicker"

                                        Title="Variation"

                                        ItemsSource="{Binding ProductVariations}"

                                        ItemDisplayBinding="{Binding Description}"

                                        IsEnabled="{Binding ProductVariations.Count}"

                                        SelectedIndexChanged="variationPicker_SelectedIndexChanged"

                                        Grid.Row="1"

                                        Grid.Column="0" />


                                <numericupdown:SfNumericUpDown x:Name="requiredQty"

                                                                Value="{Binding Quantity}"

                                                                FontAttribute="Bold"

                                                                FontSize="25"

                                                                Maximum="999999.999"

                                                                Minimum="0"

                                                                TextAlignment="Center"

                                                                TextColor="Black"

                                                                SpinButtonAlignment="Both"

                                                                StepValue="{Binding NetQuantity, Converter={StaticResource sCNumericUpDownQuantityStepValue}}"

                                                                MaximumDecimalDigits="{Binding Weighed, Converter={StaticResource sCNumericUpDownQuantityDecimalPlaces}}"

                                                                FormatString="{Binding Weighed, Converter={StaticResource sCNumericUpDownQuantityStringformat}}"

                                                                Grid.Row="2"

                                                                Grid.Column="0"

                                                                Grid.ColumnSpan="2"/>


                                <Button x:Name="addProduct"

                                        Grid.Row="3"

                                        Grid.Column="0"

                                        Grid.ColumnSpan="2"

                                        Text="Add"

                                        BackgroundColor="{StaticResource appTertiaryColour}"

                                        Pressed="addProduct_Pressed"/>

                            </Grid>

                        </Grid>

                    </DataTemplate>

                </datagrid:GridTemplateColumn.CellTemplate>

            </datagrid:GridTemplateColumn>

        </datagrid:SfDataGrid.Columns>

    </datagrid:SfDataGrid>

</forms:Grid>


3 Replies

KK Karthikraja Kalaimani Syncfusion Team August 16, 2021 12:04 PM UTC

Hi Dharminder,

Thank you for contacting Syncfusion support.

By iterating the parent  of the picker, we can get the SfNumericUpDown control of the current cell on SelectionChanged event of the picker. For more details, please refer to the below code snippets and attached sample. 

Code snippets : 
 
 private void variationPicker_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            var requiredQty = ((((sender as Picker).Parent as Grid).Parent as Grid).Parent as GridCell).Content.FindByName("requiredQty"); 
            if ((sender as Picker).SelectedItem == "India") 
            { 
                ((requiredQty as SfNumericUpDown).BindingContext as Data).No_1 = 3; 
            } 
        } 



DS Dharminder Shinh replied to Karthikraja Kalaimani August 16, 2021 01:37 PM UTC

Thank you, that worked perfectly.



KK Karthikraja Kalaimani Syncfusion Team August 17, 2021 05:34 AM UTC

Hi Dharminder, 

Thanks for the update. We glad to know that the previously provided solution has meets your requirements. Please let us know if you need further assistance from us. 

Regards,
Karthik Raja

Loader.
Up arrow icon