This is a migrated thread and some comments may be shown as answers.

Change field in row based on selection in ComboBox

3 Answers 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 26 Aug 2015, 02:48 PM

I want to be able to change the contents of a field based on what is selected in the ComboBox, so if I change selection that data in the field changes with that new selection.  When I add a row I have the field initialized to blank but based on attached image I'd like to be able to pick something in the dropdown and have blanks replaced.  I have a method now that I run during load time and if the radio buttons (Products/Completed Work) are changed that set the fields correctly, but I have found no way to run this when a different selection is made in the dropdown.  This method is located in my ViewModel code.

 Below is the code I have for the screen:

<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Visibility="{Binding IsSDI_PropertyOptionAKOperational, Converter={StaticResource VisibilityBoolConverter}}">
                                                <TextBlock Text="Products/Completed Work:" FontWeight="Bold" VerticalAlignment="Center" Margin="5,5,5,2" Height="16" />
                                                <HyperlinkButton Command="{Binding ShowUnderwritingManualCommand}" CommandParameter="PRO_ProductCoverages" Width="15">
                                                    <Canvas>
                                                        <Image Source="../Images/QuestionMark.png" Canvas.Top="4"/>
                                                    </Canvas>
                                                </HyperlinkButton>
                                            </StackPanel>

                                            <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Margin="100,5,500,2" HorizontalAlignment="right" Visibility="{Binding IsSDI_PropertyOptionAKOperational, Converter={StaticResource VisibilityBoolConverter}}">
                                                <RadioButton GroupName="ProductCoverages" Content="Yes" IsChecked="{Binding PropertyLiability.HasProductsCoverage, Mode=TwoWay}"
                                                             Command="{Binding SetProductsCoverageCommandYes}" IsEnabled="{Binding PropertyLiability.HasFarmLiability, Mode=OneWay}"/>
                                                <RadioButton GroupName="ProductCoverages" Margin="5, 0, 0, 0" Content="No" IsChecked="{Binding PropertyLiability.HasProductsCoverage, Converter={StaticResource BoolInverseConverter}, Mode=TwoWay}"
                                                             Command="{Binding SetProductsCoverageCommandNo}" IsEnabled="{Binding PropertyLiability.HasFarmLiability, Mode=OneWay}"/>
                                            </StackPanel>

                                            <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
                                                <TextBlock Text="Farm Related Business:" VerticalAlignment="Center" Margin="5,5,5,2" HorizontalAlignment="Left" TextWrapping="Wrap" FontWeight="Bold"/>
                                                <HyperlinkButton Command="{Binding ShowUnderwritingManualCommand}" CommandParameter="PRO_FarmRelated" Width="15" TabIndex="-1">
                                                    <Canvas>
                                                        <Image Source="../Images/QuestionMark.png" Canvas.Top="2" Canvas.Left="-3"/>
                                                    </Canvas>
                                                </HyperlinkButton>
                                            </StackPanel>
                                            <Button Grid.Row="1" Grid.Column="2" Click="Button_Click" HorizontalAlignment="Right" VerticalAlignment="Center" IsEnabled="{Binding PropertyLiability.HasFarmLiability, Mode=OneWay}">
                                                <TextBlock  Text="Add Farm Related Business"  />
                                            </Button>



                                            <telerik:RadGridView Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="10" Margin="5,0,0,5"  
                    x:Name="radGridView_FarmBusiness"
                    AutoGenerateColumns="False" 
                    IsFilteringAllowed="False"
                    ShowGroupPanel="False"
                    CanUserFreezeColumns="False"
                    CanUserInsertRows="True"
                    CanUserReorderColumns="False"
                    RowIndicatorVisibility="Collapsed" 
                    ValidatesOnDataErrors="InEditMode"
                    AddingNewDataItem="radGridViewFarmBusiness_AddingNewDataItem"
                    RowEditEnded="radGridViewFarmBusiness_RowEditEnded"
                    RowValidating="radGridViewFarmBusiness_RowValidating"
                    telerik:StyleManager.Theme="{StaticResource CustomTheme}" 
                    ItemsSource="{Binding IncidentalFarmBusinessList, Mode=TwoWay}" 
                                                                                                                                              EditTriggers="CellClick" IsEnabled="{Binding PropertyLiability.HasFarmLiability, Mode=OneWay}">
                                                <telerik:RadGridView.Columns>
                                                    <telerik:GridViewColumn Width="90" IsVisible="{Binding DataSource.AllowEdits, Source={StaticResource DataContextProxy}}">
                                                        <telerik:GridViewColumn.CellTemplate>
                                                            <DataTemplate>
                                                                <Button Content="Delete" Click="Delete_Click" />
                                                            </DataTemplate>
                                                        </telerik:GridViewColumn.CellTemplate>
                                                    </telerik:GridViewColumn>

                                                    <telerik:GridViewDataColumn Header="Type" MinWidth="190"
DataMemberBinding="{Binding IncidetnalFarmBusiness}"  FilterMemberPath="IncidentalFarmBusinessType.Description">
                                                        <telerik:GridViewDataColumn.CellTemplate>
                                                            <DataTemplate>
                                                                <TextBlock Text="{Binding IncidentalFarmBusinessType.Description, Mode=TwoWay}" />
                                                            </DataTemplate>
                                                        </telerik:GridViewDataColumn.CellTemplate>
                                                        <telerik:GridViewDataColumn.CellEditTemplate>
                                                            <DataTemplate>
                                                                <telerikInput:RadComboBox
IsEditable="True"
ItemsSource="{Binding DataSource.IncidentalFarmBusinessTypeList, Source={StaticResource DataContextProxy}}"
                                                                                 DisplayMemberPath="Description"                                                                 
SelectedValue="{Binding IncidentalFarmBusinessType, Mode=TwoWay}"/>
                                                            </DataTemplate>
                                                        </telerik:GridViewDataColumn.CellEditTemplate>
                                                    </telerik:GridViewDataColumn>

 

Just not sure if this can be done and if so how or where to look to find some examples of how to do this.

Thanks for any help you can give me or point me in the direction of what/where to look to do something like this.

Regards,

-- Jim

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 31 Aug 2015, 07:58 AM
Hi Jim,

Based on the provided description we created a sample project that we believe reproduces your scenario and it seems everything works as expected on our side - when an item inside RadComboBox is selected the text inside the field updates as expected. Please, check the attached sample project and let us know if that is what you are looking for and if we didn't miss something in order to reproduce the observed by you issue.

What we could also suggest you is to consider using the build in for RadGridView GridViewComboBoxColumn instead of RadComboBox. Please. check the following article for a more detailed information:
http://docs.telerik.com/devtools/silverlight/controls/radgridview/columns/columntypes/column-types-combobox-column

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jim
Top achievements
Rank 1
answered on 31 Aug 2015, 01:28 PM

Nasko,

Looks like I for got to include source for the field that I want to change when I make a selection (see the yellow highlighted sections in the original attached image).

When a selection is made in theComboBox I am wanting to change value that is in that field based on the selection.  Below is the source that I have for that field.

 <telerik:GridViewColumn Header="Products Coverage" IsVisible="{Binding DataSource.Is_PropertyOptionMExpandedOperational, Source={StaticResource DataContextProxy}}">                                                         <telerik:GridViewColumn.CellTemplate>                                                             <DataTemplate>                                                                 <TextBlock Text="{Binding ProductCoverageAllowed, Mode=OneWay}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" /> <!--Visibility ="{Binding PropertyLiability.HasProductsCoverage, Source={StaticResource DataContextProxy}}"/>-->                                                             </DataTemplate>                                                         </telerik:GridViewColumn.CellTemplate>                                                     </telerik:GridViewColumn>

 

Like I said I have a method that will set the field but can not figure out how to call that when a selection is changed in the dropdown.  Sorry if I wasn't clear on this before.

-- Jim

0
Nasko
Telerik team
answered on 03 Sep 2015, 06:58 AM
Hi Jim,

I apologize for the misunderstanding. We could suggest you two approaches that you could use in order to get notified when an item from RadComboBox gets selected.

1. You could use the SelectedValue property. When you select an item from RadComboBox the set implementation of the SelectedValue property will be called and inside it you could call the method that set the value of the desired field - please, notice the property to which the SelectedValue is bound to should be placed inside the ViewModel and the Source of the binding needs to be that ViewModel.

2. As a second approach we could suggest you and believe will more suit your requirements is to use the SelectionChanged event of RadComboBox. By using the EventToCommandBehavior you could bind the event to a command inside  your ViewModel. So, when a selection is made the Command will be executed it and inside it again you could call the needed method.

We have modified the sample project with the described second approach and you could run and evaluate it.

We hope this will help you.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ComboBox
Asked by
Jim
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Jim
Top achievements
Rank 1
Share this question
or