GridViewComboBoxColumn dropdown list font does not follow parent grid font

8 posts, 2 answers
  1. Ian
    Ian avatar
    5 posts
    Member since:
    Apr 2011

    Posted 05 Apr 2011 Link to this post

    Hello there,

    I have changed the default Segoe font to Arial 9pt for my RadGridView using the IDE. But the drop-downlist of items in a GridViewComboBoxColumn does not follow and still displays as Segoe. There is no option in the IDE to alter it. I am trying to find out how to alter the font of the drop-down list in code please? (vb.net)

    I imagine I could use VisualStyle builder but I cannot seem to export from that all the settings for a given off-the-shelf theme, and I do not havethe time to make a whole theme with all it's settings...

    Thanks in advance
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 05 Apr 2011 Link to this post

    Hello Ian,

    You can set a different font for the DropDown by subscribing to the CellEditorInitialized event as follows:

    private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        var editor = e.ActiveEditor;
        if (editor != null && editor is RadDropDownListEditor)
        {
            RadDropDownListEditor dropDown = (RadDropDownListEditor)editor;
            RadDropDownListEditorElement element = (RadDropDownListEditorElement)dropDown.EditorElement;
            element.Font = // a font
            element.ListElement.Font = // a font
        }
    }

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ian
    Ian avatar
    5 posts
    Member since:
    Apr 2011

    Posted 07 Apr 2011 Link to this post

    Thank you Richard
    That worked once I managed to convert it to vb.
    Thanks again.
  5. Ian
    Ian avatar
    5 posts
    Member since:
    Apr 2011

    Posted 07 Apr 2011 Link to this post

     

     

     

    Dim editor = e.ActiveEditor
    If editor IsNot Nothing AndAlso TypeOf editor Is RadDropDownListEditor Then
        Dim dropDown As RadDropDownListEditor = DirectCast(editor, RadDropDownListEditor)
        Dim element As RadDropDownListEditorElement = DirectCast(dropDown.EditorElement, RadDropDownListEditorElement)
        element.Font = New Font("Arial", 9)
        element.ListElement.Font = New Font("Arial", 9)
    End If

     

     

     

  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Apr 2011 Link to this post

    Hi,

    Glad that helped. Just one other thing. You may have already realised but it would be better to maintain a private member of the font that you need and assign that rather than create a new instance of the font each time CellEditorInitialized is raised.

    Hope that helps
    Richard
  7. Ian
    Ian avatar
    5 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    Thanks Richard, yes. I had guessed as much and will do so.
    Thanks so much for your help!
  8. Zeone Informatica
    Zeone Informatica avatar
    7 posts
    Member since:
    Dec 2011

    Posted 11 Mar 2014 Link to this post

    Hi there, I'm having the same issue, I've tested Richard Slade code, and it worked but when I type something in the autocomplete area the font changes again to the default value..

    Any sugestion?  

    Thanks
  9. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 14 Mar 2014 Link to this post

    Hello Jose,

    The observed behavior is expected, as the auto complete functionality has its own popup with its own ListElement in it, so you have to set the Font of the latter as well. Here is the modified snippet:
    Font f = new Font("Consolas", 12);
    private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        var editor = e.ActiveEditor;
        if (editor != null && editor is RadDropDownListEditor)
        {
            RadDropDownListEditor dropDown = (RadDropDownListEditor)editor;
            RadDropDownListEditorElement element = (RadDropDownListEditorElement)dropDown.EditorElement;
            element.Font = f;
            element.ListElement.Font = f;
            element.AutoCompleteSuggest.DropDownList.ListElement.Font = f;
        }
    }

    I hope that the provided information addresses your question.

    Best wishes,
    Stefan
    the Telerik team
     
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready