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

GridViewComboBoxColumn styles in code

2 Answers 327 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gord
Top achievements
Rank 1
Gord asked on 15 Apr 2016, 02:52 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 18 Apr 2016, 11:07 AM
Hi,

When using our NoXAML , 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.
0
Gord
Top achievements
Rank 1
answered on 18 Apr 2016, 12:01 PM

Hello Yoan,

Works like a charm.  Thank you! 

Tags
GridView
Asked by
Gord
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Gord
Top achievements
Rank 1
Share this question
or