wpf c# RadPropertyGrid RadComboBox --> Set Seloected index or Text Programmatically

1 Answer 32 Views
PropertyGrid
BerndR
Top achievements
Rank 1
Iron
BerndR asked on 05 Dec 2024, 08:46 AM

Hi,

Does anyone know how I can set the text manually in a RadPropertyGrid and a ComboBox? Or also the selectedIndex? I want to manually set ONLY this one element.


               <telerik:RadPropertyGrid AutoGeneratePropertyDefinitions="False"
                                     x:Name="PropertyBenutzer"  
                                     LabelColumnWidth="150" 
                                     MinHeight="50" 
                                     FontFamily="Tahoma" 
                                     FontWeight="Bold" 
                                     FontSize="12" 
                                     DescriptionPanelVisibility="Visible"
                                     CanUserResizeDescriptionPanel="True"
                                     telerik:StyleManager.Theme="Crystal"
                                     NestedPropertiesVisibility="Visible" 
                                     RenderMode="Flat"
                                     IsGrouped="True"
                                     Item="{Binding ElementName=MyPropertyGrid1}" 
                                     Canvas.Left="568" 
                                     >
...
                        <telerik:PropertyDefinition DisplayName="Anrede" OrderIndex="1" GroupName="Benutzer">
                            <telerik:PropertyDefinition.EditorTemplate>
                                <DataTemplate>
                                    <Border>
                                        <telerik:RadComboBox x:Name="ComboBoxAnrede" 
                                                         FontFamily="Tahoma" 
                                                         Width="156" 
                                                         HorizontalAlignment="Left" 
                                                         HorizontalContentAlignment="Center" 
                                                         SelectedItem="{Binding Anrede, Mode=TwoWay}"
                                                         ItemsSource="{Binding AnredeListe}"
                                                         DisplayMemberPath="Anrede"
                                                         IsEditable="False"
                                                         IsEnabled="true"
                                                         IsReadOnly="False"
                                                         MinWidth="30"
                                                         SelectedIndex="0" 
                                                         CanAutocompleteSelectItems="True" 
                                                         CanKeyboardNavigationSelectItems="True"
                                                         >
                                        </telerik:RadComboBox>
                                    </Border>
                                </DataTemplate>
                            </telerik:PropertyDefinition.EditorTemplate>
                        </telerik:PropertyDefinition>

 

 

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 09 Dec 2024, 01:07 PM

Hello Bernd,

Thank you for the shared information.

Based on the provided code snippets, the best approach here would be to work with the property that is bound to the SelectedItem property of the RadComboBox inside the EditorTemplate. The property that I am referring to is the one named "Anrede" in the second code snippet that you shared. Since the Binding instance for the SelectedItem property has its Mode property set to TwoWay, it means that it can be changed from both the UI, as well as from the view model. 

Generally, in scenarios where such a requirement is needed, it is suggested to work with either the SelectedItem property or with the SelectedIndex one. Since the SelectedItem property is already utilized on your side in an MVVM manner, it would be the most suitable approach.

With this being said, I prepared a sample project for you to test, which contains a sample implementation of the above suggestion. It produces the following result:

I hope the provided information and example will be of help to you. Let me know if any additional assistance is required.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PropertyGrid
Asked by
BerndR
Top achievements
Rank 1
Iron
Answers by
Stenly
Telerik team
Share this question
or