CreateDefaultColumn shouldn't be hard coded

Aug 12, 2008 at 6:46 PM
We should be able to provide factory methods/objects that would be able to generate appropriate DataGridColumn's based on data types.  It would also be useful to be able to specify these factories on DataGrid instances, instead of being a global/static factory method.  Yes, it's possible to provide our own column types on a case by case basis, but this isn't as convenient as the auto-generation mechanism.  Just consider something as simple as a Color data type that you'd like to always use a (user created) DataGridColorPickerColumn, for instance.
Aug 14, 2008 at 6:31 PM
Try this.

<DataGrid AutoGenerateColumns="true" AutoGeneratingColumn="OnAutoGeneratingColumn" ItemsSource="{Binding someDataSet}">

public partial class Window1 : Window
    private void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        if (e.PropertyType == typeof(Color))
            DataGridBoundColumn oldColumn = (DataGridBoundColumn)e.Column;
            DataGridBoundColumn newColumn = new DataGridColorPickerColumn();
            newColumn.DataFieldBinding = oldColumn.DataFieldBinding;
            newColumn.Header = oldColumn.Header;
            e.Column = newColumn;

Varsha (MSFT)

Aug 14, 2008 at 8:51 PM
Thanks.  I missed that.  Exactly what I was asking for.