【问题标题】:data binding combobox in GridViewGridView 中的数据绑定组合框
【发布时间】:2018-01-12 12:49:05
【问题描述】:

我在 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 >

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

非常感谢您的时间!

【问题讨论】:

  • 您将所有 RadComboBox 的 Text 属性绑定到相同的源属性。您在 GridView 中显示的每篇文章都应该有自己的 Description 属性。

标签: wpf gridview data-binding combobox telerik


【解决方案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>

【讨论】:

    猜你喜欢
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2012-01-24
    • 1970-01-01
    • 2017-11-16
    相关资源
    最近更新 更多