views:

23

answers:

1

Hello,

Why is the ComboBox in that column only visible via double-click in the empty cell when the DataGrid is set to IsReadOnly = FALSE ???

 <DataGridComboBoxColumn Width="*" IsReadOnly="False" Header="test" />

using a DataTemplateColumn works as always... whats wrong with that DataGridComboBoxColumn?

works:

<DataGridTemplateColumn Header="Schoolclass">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Background="Blue" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
A: 

All builtin DataGridColumns have two styles. One for when the cell is not in editing mode and one where the cell is in editing mode. Usually the non editing mode simply displays a textblock, not the actual control you might expect (ComboBox, TextBox, etc). And once you start editing the cell, the textblock is replaced with the appropriate control. If you have the datagrid set to IsReadOnly = true, then that means the cells never go to their editing mode and that is the behaviour you are seeing.

When creating a DataGridTemplateColumn you are essentialy replacing all the built in datagrid logic. As an example if you want your templated column to be readonly when the datagrid is readonly, then you have to manually bind the two values together. And if you wanted to get the same behaviour as the builtin columns (textblock when cell is not in editing mode), then you'd have to use triggers to supply the appropriate controltemplates.

Also note, that if you are using a built in column (eg DataGridCheckBoxColumn) and you speficy an ElmentStyle for it (for instance to center the checkBoxes) then the column's cells are all editable despite datagrid being set to IsReadOnly = true. This happens because when you specify an ElmentStyle you are replacing the builtin Style, which contains logic to make the checkboxes readonly when the datagrid is readonly.

Marko
already found that out ;-) But nice summary :)
msfanboy