Styling DataGridCOmboboxColumn...

Editors for WPF Forum

Posted 10 years ago by Jack Stephenson
Version: 14.1.0601
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

Am autogenerating columns in a datagrid

The DataGridCOmboboxColumn generated is not styled.

How do I fix this?

Comments (3)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

If you use Reflector and look at the source of DataGridComboBoxColumn.GenerateEditingElement, they apply a Style to the ComboBox.  Therefore our themed implicit Style that targets ComboBox (assuming your have our native themes on) won't be able to apply to it.  You'd probably need to override that method and clear out the Style value.


Actipro Software Support

Answer - Posted 10 years ago by Jack Stephenson
Avatar

Great Response.

Derived a class from ThemedGrid.

Overroad this method.

YOu might want to consider this in your implementation

protected override void OnAutoGeneratingColumn(DataGridAutoGeneratingColumnEventArgs e)
{
   if (e.Column is DataGridComboBoxColumn)
   {
      ((DataGridComboBoxColumn) e.Column).EditingElementStyle = null;
      ((DataGridComboBoxColumn)e.Column).ElementStyle = null;
   }  

   base.OnAutoGeneratingColumn(e);
}

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jack,

We've updated the next maintenance release to apply our themed styles for ComboBox and CheckBox columns that are auto-generated per that method override you mentioned.  However please note that it will only work for auto-generated columns.  If you explicitly define your columns, you'd still have to manually apply a style.

That being said, there is an easier way to do the style when not using auto-generated columns.  You'd set these two properties like this:

<DataGridComboBoxColumn MinWidth="100" 
 ElementStyle="{StaticResource {x:Static themes:SharedResourceKeys.ComboBoxStyleKey}}"
 EditingElementStyle="{StaticResource {x:Static themes:SharedResourceKeys.ComboBoxStyleKey}}" />


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.