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

PropertyGridDropDownListEditor with icons

5 Answers 117 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Veteran
Valery asked on 02 Jan 2018, 06:56 AM
I need an PropertyGridDropDownListEditor with icons.
How can I do that?

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Jan 2018, 11:11 AM
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.
0
Valery
Top achievements
Rank 1
Veteran
answered on 02 Jan 2018, 12:12 PM
Thank you. This useful example would be nice to insert into online documentation "PropertyGrid - Editors"
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Jan 2018, 12:23 PM
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.
0
Cesar
Top achievements
Rank 1
answered on 31 May 2019, 04:40 AM
It could be posible to get an example in VB.NET.  ?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 31 May 2019, 10:29 AM
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.
Tags
PropertyGrid
Asked by
Valery
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Valery
Top achievements
Rank 1
Veteran
Cesar
Top achievements
Rank 1
Share this question
or