PropertyGridDropDownListEditor with icons

6 posts, 0 answers
  1. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 02 Jan 2018 Link to this post

    I need an PropertyGridDropDownListEditor with icons.
    How can I do that?
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3378 posts

    Posted 02 Jan 2018 Link to this post

    Hello, Valery, 

    Thank you for writing.  

    In the RadPropertyGrid.EditorInitialized event you can subscribe to the VisualItemFormatting event of the BaseDropDownListEditorElement. Thus, you can assign images to the visual items.



    Here is a sample code snippet which result is illustrated in the attached screenshot below:
    private void radPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e)
    {
        PropertyGridDropDownListEditor editor = e.Editor as PropertyGridDropDownListEditor;
        if (editor!=null && e.Item.Name=="TextAlign")
        {
            BaseDropDownListEditorElement element = editor.EditorElement as BaseDropDownListEditorElement;
            element.VisualItemFormatting-=element_VisualItemFormatting;
            element.VisualItemFormatting+=element_VisualItemFormatting;
        }
    }
     
    private void element_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
    {
        args.VisualItem.Image = GetImageByText(args.VisualItem.Text);
    }
     
    private Image GetImageByText(string align)
    {
        if (align=="Left")
        {
            return Properties.Resources.Format_Align_Left;
        }
        else if (align=="Right")
        {
            return Properties.Resources.Format_Align_Right;
        }
        return Properties.Resources.Format_Align_Center;
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 02 Jan 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you. This useful example would be nice to insert into online documentation "PropertyGrid - Editors"
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3378 posts

    Posted 02 Jan 2018 Link to this post

    Hello, Valery, 

    Thank you for writing back. 

    I am glad that the provided code snippet was useful. We will insert a similar example in the relevant articles for RadPropertyGrid in the future improvement of the documentation.

    I hope this information helps. If you have any additional questions, please let me know. 

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Cesar
    Cesar avatar
    6 posts
    Member since:
    May 2019

    Posted 30 May in reply to Dess | Tech Support Engineer, Sr. Link to this post

    It could be posible to get an example in VB.NET.  ?
  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3378 posts

    Posted 31 May Link to this post

    Hello, Cesar,     

    Please refer to the below VB.NET equivalent of the solution:

    Public Sub New()
        InitializeComponent()
        Me.RadPropertyGrid1.SelectedObject = New RadTextBox()
        Me.RadPropertyGrid1.ToolbarVisible = True
        AddHandler   Me.RadPropertyGrid1.EditorInitialized, AddressOf radPropertyGrid1_EditorInitialized
    End Sub
     
    Private Sub radPropertyGrid1_EditorInitialized(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs)
        Dim editor As PropertyGridDropDownListEditor = TryCast(e.Editor, PropertyGridDropDownListEditor)
     
        If editor IsNot Nothing AndAlso e.Item.Name = "TextAlign" Then
            Dim element As BaseDropDownListEditorElement = TryCast(editor.EditorElement, BaseDropDownListEditorElement)
            RemoveHandler  element.VisualItemFormatting,AddressOf element_VisualItemFormatting
            AddHandler  element.VisualItemFormatting,AddressOf element_VisualItemFormatting
        End If
    End Sub
     
    Private Sub element_VisualItemFormatting(ByVal sender As Object, ByVal args As VisualItemFormattingEventArgs)
        args.VisualItem.Image = GetImageByText(args.VisualItem.Text)
    End Sub
     
    Private Function GetImageByText(ByVal align As String) As Image
        If align = "Left" Then
            Return My.Resources.Format_Align_Left
        ElseIf align = "Right" Then
            Return My.Resources.Format_Align_Right
        End If
     
        Return My.Resources.Format_Align_Center
    End Function

    Feel free to use our online code converter for converting C# to VB and vice versa: http://converter.telerik.com/

    I hope this information helps. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top