-1

After wasting 2 day, I just little understand of wpf datagrid data-binding process.In the Earlier,I want to show combo box in datagrid view column.After googled, i found the way to bind combo in datagrid.Now i got the problem that looks like easy but it make me crazy.

This is Initial state.In this state,Combo box is missing.

enter image description here

After double click the row,it visible.

enter image description here

How can i show combo box in Initial state? Thank You.

lwin
  • 3,784
  • 6
  • 25
  • 46

1 Answers1

1

There'are two templates used in DataGrid:

  1. CellTemplate
  2. CellEditingTemplate

CellTemplate acts a role of, as you said, initial state, whereas CellEditingTemplate is used when you edit a cell. For instance, DataGridTextColumn is actually looks like this:

<DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding SomeField}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding SomeField}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>
JohnyL
  • 6,894
  • 3
  • 22
  • 41
  • Thanks you for showing me example of Cell Template and Cell Editing Template. – lwin Dec 29 '17 at 02:55
  • Please can you explain me for another problem?:) – lwin Dec 29 '17 at 08:07
  • @Jze Go ahead :) – JohnyL Dec 29 '17 at 08:54
  • After updated the cell value of datagrid, List in Viewmodel will auto update? Let me show you example=>https://stackoverflow.com/questions/48020099/observablecollection-is-not-update-after-datagrid-cell-change Thanks – lwin Dec 29 '17 at 09:36