GridViewComboBoxColumn styles in code

3 posts, 1 answers
  1. Gord
    Gord avatar
    20 posts
    Member since:
    Jul 2014

    Posted 15 Apr Link to this post

    Hello,

    I was going over the documentation page for a combo box column in a RadGridView.  The "one click" solution shows adding styles to the Column definition in XAML to set "OpenDropDownOnFocus" to true.

    Is there a way this can be accomplished in code?  I am using the NoXaml binaries.  I tried the following:

    var col = new GridViewComboBoxColumn { DataMemberBinding = new Binding("Lookup") };
    col.ItemsSourceBinding = new Binding("Lookups");
    col.EditorStyle = new Style(typeof(RadComboBox));  // Editor Style is null by default
    col.EditorStyle.Setters.Add(new Setter {
      Property = RadComboBox.OpenDropDownOnFocusProperty,
      Value = true
    });
    // Item template displays other properies in the "Lookup" object.
    col.ItemTemplate = (DataTemplate)Application.Current.Resources["lookup"];

    But when the grid renders now, the dispaly works, but the editor for the combobox columns no longer have content. 

    Since I'm using the NoXaml binaries, do I need to explicitly define the EditorTemplate as well because the EditorStyle overrides the implicit template?

  2. Answer
    Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 18 Apr Link to this post

    Hi,

    When using our NoXAML dlls, you need to base the style using the BaseOn attribute. Please check the following code snippet for a reference:
    var style = new Style(typeof(RadComboBox));  // Editor Style is null by default
                style.BasedOn = (Style)FindResource(typeof(RadComboBox));
                style.Setters.Add(new Setter
                {
                    Property = RadComboBox.OpenDropDownOnFocusProperty,
                    Value = true
                });
     
                col.EditorStyle = style;


    Regards,
    Yoan
    Telerik
    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
  4. Gord
    Gord avatar
    20 posts
    Member since:
    Jul 2014

    Posted 18 Apr in reply to Yoan Link to this post

    Hello Yoan,

    Works like a charm.  Thank you! 

Back to Top