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

Simple drop down editor?

1 Answer 237 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Karl B
Top achievements
Rank 1
Karl B asked on 18 Aug 2016, 09:38 PM

How can I make this work with the property grid?  I am using a property grid with automatically generated properties and on edit I want SelectedIndex1 and SelectedIndex2 to display a list of my available indexes for the user to choose from.

public class MyIndexSelector
{
    private readonly List<int> m_someList = new List<int> () {1, 2, 3};
    [Browsable (false)]
    public List<int> AvailableIndexes { get { return m_someList; } }
 
    //??[Telerik.Windows.Controls.Data.PropertyGrid.Editor (typeof (IndexEditorControl), Telerik.Windows.Controls.Data.PropertyGrid.EditorStyle.DropDown)]
    public int SelectedIndex1 { get; set; }
 
    //??[Telerik.Windows.Controls.Data.PropertyGrid.Editor (typeof (IndexEditorControl), Telerik.Windows.Controls.Data.PropertyGrid.EditorStyle.DropDown)]
    public int SelectedIndex2 { get; set; }
}

 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 19 Aug 2016, 11:49 AM
Hello Karl,

The suggested approach in this scenario would be to create a custom DataTemplate and set that as the EditorTemplate for the PropertyDefinitions of interest in RadPropertyGrid's AutoGeneratingPropertyDefinition event:

private void RadPropertyGrid_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
{
    if (e.PropertyDefinition.SourceProperty.Name == "Country")
    {
        e.PropertyDefinition.EditorTemplate = (DataTemplate)Application.Current.Resources["ComboBoxTemplate"];
    }
}

<Application.Resources>
    <DataTemplate x:Key="ComboBoxTemplate">
        <telerik:RadComboBox ItemsSource="{Binding Countries}" SelectedValue="{Binding Country}" />
    </DataTemplate>
</Application.Resources>

I'm attaching a sample project to better demonstrate this. Please have a look at it and let me know whether such an approach would work for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PropertyGrid
Asked by
Karl B
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or