0
votes

I am trying to add a combobox to a Xceed WPF datagrid but not able to bind Itemssource to the combo box. Here is the xaml for the datagrid.

<xwpf:DataGridControl ItemsSource="{Binding SaleDetails}" AutoCreateColumns="False"  >
        <xwpf:DataGridControl.Columns>
            <xwpf:Column FieldName="Status" Title="Status" CellContentTemplate="{StaticResource colReinstatementType}" CellEditor="{StaticResource statusEditor}" />
        </xwpf:DataGridControl.Columns>
</xwpf:DataGridControl>

Resources

    <UserControl.Resources>
    <DataTemplate x:Key="colReinstatementType">
            <ComboBox BorderThickness="0"
                      x:Name="cmbStatus1"
                      IsReadOnly="False"
                      IsEditable="True"
                      MinHeight="20"
                      DisplayMemberPath="part_no"
                      Text="{xwpf:CellEditorBinding NotifyOnSourceUpdated=True}"  
                      SelectedItem="{Binding Item, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      ItemsSource="{Binding AvailablePartMaterial, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
            </ComboBox>
        </DataTemplate>
        <xwpf:CellEditor x:Key="statusEditor">
            <xwpf:CellEditor.EditTemplate>
                <DataTemplate>
                    <ComboBox BorderThickness="0"
                              x:Name="cmbStatus"
                              IsReadOnly="False"
                              IsEditable="True"
                              MinHeight="20"
                              DisplayMemberPath="part_no"
                              Text="{xwpf:CellEditorBinding NotifyOnSourceUpdated=True}"  
                              SelectedItem="{Binding Item, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              ItemsSource="{Binding AvailablePartMaterial, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                    </ComboBox>
                </DataTemplate>
            </xwpf:CellEditor.EditTemplate>
        </xwpf:CellEditor>            
     </UserControl.Resources>

Item and AvailablePartMaterial do exist in the SaleSheet type whose collection is bound to the datagrid. Even Item property does get fired which means Selected item of the combo box is getting binded. But no data is shown in the combo box.

1
Can you check the output window for binding failure logs?user1672994
thr is no binding failure in the output windowWAQ

1 Answers

2
votes

The CellContentTemplate is meant for display purposes only. Usually it is used to display text using something like a TextBlock. In the cases where an editor type must be used (such as a CheckBox on a Boolean column), you will want to make it ReadOnly to avoid any unwanted issues.

In your case, you have a ComboBox with a CellEditorBinding as the CellContentTemplate. The CellEditorBinding only works in a CellEditor, so if the user is editing the row's value by using the CellContentTemplate's ComboBox, it will have no impact on the underlying value.

For your bindings, try something like this instead:

SelectedValuePath="part_no"   // name of column used to identify which record is selected
DisplayMemberPath="part_name" // name of column used to indicate the text/value to display
SelectedValue = {xwpf:CellEditorBinding} // SelectedItem or SelectedIndex can be used instead, depending on the situation/data

In regards to the ItemsSource, you cannot bind to it directly while you are inside a CellEditor's DataTemplate, you need to indicate where it is located. For example:

ItemsSource="{Binding Source={x:Static Application.Current}, Path=MyData}">