Simple drop down editor?

2 posts, 0 answers
  1. Karl
    Karl avatar
    35 posts
    Member since:
    Dec 2013

    Posted 18 Aug Link to this post

    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; }
    }

     

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 19 Aug Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top