2

Have a datagrid with autogeneratecolumn

<DataGrid ItemsSource="{Binding Table}"
          CanUserSortColumns="False"
          CanUserAddRows="False"
          CanUserDeleteRows="False"
          SelectionUnit="Cell"
          AutoGenerateColumns="True">

I need all the columns after 1 to have their DataGridTemplateColumn. DataGridTemplateColumn:

<DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding ColumnN}" Background="Red"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
        <DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <TextBox Text="{Binding ColumnN}"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellEditingTemplate>
    </DataGridTemplateColumn>

ColumnN is the specific name for the column that will be Binding. There is no model. But if there is a solution somehow through the model, then it might work. But also with autogeneration.

  • 2
    i think autogenerate is pretty much an `all or nothing` type of feature – jazb Nov 02 '18 at 03:15
  • Agreed, `AutoGenerateColumns` is generally not a very useful feature for anything but the simplest cases. You may be tempted to define a `CellStyle`, but you'll find yourself stuck trying to figure out the bindings. You will need to pre-define all your columns. – Nik Nov 02 '18 at 03:39
  • @Nik , number of columns unknown – Serious Down Nov 02 '18 at 04:52
  • 1
    modify generated column in AutoGeneratingColumn event of DataGrid. see example https://stackoverflow.com/questions/40358111/datagrid-shows-path-of-image-instead-of-image-itself – ASh Nov 02 '18 at 07:55

0 Answers0