views:

272

answers:

0

Having successfully used DataGridTextColumn a few times, I was unprepared for the difficulty I encountered using DataGridComboBoxColumn.

I can bind an int field in a class to DataGridTextColumn, but I have failed completely to bind the same field to DataGridComboBoxColumn. When the screen is displayed, the DataGridTextColum contains a value, but the DataGridComboTox does not. The list will drop down and I can select an item, but when I tab away, no value is displayed. The DataGrid is in a DataTemplate which is bound to a TabControl.

I have read everything on DataGridComboBoxColumn here on SO and on a number of other sites. I'm missing something and I don't know what it is. Any advice, and especially sample code that is similar, would be much appreciated.

Here are some relevant snippets from my code.

<DataTemplate DataType="{x:Type ViewModel1:PageDetail}">
    <Grid>
        <toolkit:Grid Row="0" Grid.Column="0"
            ItemsSource="{Binding Path=ItemDetails}"
            SelectedItem="{Binding Path=SelectedItemDetail, Mode=TwoWay}">
            <toolkit:DataGrid.Columns>
                <toolkit:DataGridTextColumn Header="Loop as Text">
                    <toolkit:DataGridTextColumn.Binding>
                        <Binding Path="Loop" Mode="TwoWay"></Binding>
                    </toolkit:DataGridTextColumn.Binding>
                </toolkit:DataGridTextColumn>

                    <toolkit:DataGridComboBoxColumn Header="Loop as ComboBox">
                    <toolkit:DataGridComboBoxColumn.SelectedItemBinding>
                        <Binding Path="Loop" Mode="TwoWay"></Binding>
                    </toolkit:DataGridComboBoxColumn.SelectedItemBinding>
                    <toolkit:DataGridComboBoxColumn.ItemsSource>
                        <collections:ArrayList>
                            <system:string>Unused</system:String>
                            <system:string>Armed</system:String>
                        </collections:ArrayList>
                    </toolkit:DataGridComboBoxColumn.ItemsSource>
                </toolkit:DataGridTextColumn>
            </toolkit:DataGrid.Columns>
        </toolkit:Grid>
    </Grid>
</DataTemplate>

<StackPanel>
    <TabControl ItemsSource="{Binding Path=PageDetails}"
                SelectedItem="{Binding Path=SelectedPageDetail, Mode=TwoWay}">
    </TabControl>
</StackPanel>

public class ItemDetail : ViewModelBase
{
    private int _loop;
    public int Loop
    {
        get { return _loop; }
        set 
        {
            _loop = value;
            OnPropertyChanged("Loop");
        }
    }
}