开发者

Using a databound combobox on a datagrid

With a datagrid, I want to use a databound combobox to set the val开发者_JAVA百科ue of a property with the combobox's selected value. How would I go about doing that?

Cheers


This can easily be achieved using the WPF DataGrid's CellTemplate features:

<DataGrid.Columns>
    <DataGridTemplateColumn Header="My Column">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding MyBoundField}"/>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
        <DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <ComboBox ItemsSource="{Binding MyOptionsSource}" IsEditable="False"/>
            </DataTemplate>
        <DataGridTemplateColumn.CellEditingTemplate>
    </DataGridTemplateColumn>
<DataGrid.Columns/>

Now just handle the ComboBox SelectionChanged event and force a Commit by giving the DataGrid keyboard focus :)

Have fun.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜