GridView中的数据绑定组合框

时间:2018-01-12 12:49:05

标签: wpf gridview data-binding combobox telerik

我在GridView中使用此示例中的ComboBox作为CellEditTemplate:

    <telerik:GridViewDataColumn Header="َArticle Description" Width="100">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding DataContext.AccDocumentItem.Description1, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"/>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
            <telerik:GridViewDataColumn.CellEditTemplate>
                <DataTemplate>
                    <telerik:RadComboBox IsEditable="True" DisplayMemberPath="SLStandardDescriptionTitle"
                              ItemsSource="{Binding DataContext.AccDocumentItem.SelectedSL.SLStandardDescriptions, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" 
                              Text="{Binding DataContext.AccDocumentItem.Description1,Mode=TwoWay,RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="DropDownOpened">
                                <i:InvokeCommandAction Command="{Binding DataContext.SLStandardDescriptionsDropDownOpenedCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" CommandParameter="DLType2"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </telerik:RadComboBox>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellEditTemplate>
        </telerik:GridViewDataColumn >

我需要提供一个网格,其中一列是组合框。用户可以从列表中选择一个值或输入新值,问题是所有行中都会重复选定的行。你能告诉我我做错了吗?

您的时间非常感谢!

1 个答案:

答案 0 :(得分:1)

试试这段代码:

        <telerik:GridViewDataColumn Header="Article Description" Width="100">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Description1}"/>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
            <telerik:GridViewDataColumn.CellEditTemplate>
                <DataTemplate>
                    <telerik:RadComboBox IsEditable="True" DisplayMemberPath="SLStandardDescriptionTitle"
                              ItemsSource="{Binding DataContext.AccDocumentItem.SelectedSL.SLStandardDescriptions, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" 
                              Text="{Binding Description1,Mode=TwoWay}">
                    </telerik:RadComboBox>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellEditTemplate>
        </telerik:GridViewDataColumn>