2

注意:此条目属于“分享您的知识,问答风格”类型。我在下面回答我自己的问题。

不幸的是,在具有 Master-Detail 的 DevExpress 网格中,SelectedItem不适用于子网格。

如何确定在子网格中选择了哪个项目?

4

2 回答 2

1

这已被取代:-

请注意,这种方法从 15.1 版开始已经过时,在该版本中,开箱即用地支持绑定主网格和详细网格的选择。从该版本开始,直接绑定 CurrentItem/SelectedItem/SelectedItems 属性,如Master-detail grid - Add the capability to bind selection and navigation properties中所述。

主从网格的以下属性现在支持绑定:SelectedItemCurrentItemSelectedItems。指定DataControlDetailDescriptor.ParentPath属性或处理DataControlDetailDescriptor.CustomGetParent事件以启用从 ViewModel 到网格的绑定。

于 2016-04-25T20:32:00.253 回答
0

注意:此条目属于“分享您的知识,问答风格”类型。我在上面回答我自己的问题。

在为此苦苦挣扎了一段时间后,我发现解决此问题的最佳方法是按照以下说明创建自己的附加属性:

https://www.devexpress.com/Support/Center/Example/Details/E4402

这是一些示例代码,展示了它是如何工作的。该方法取决于 DevExpress 库的版本,如上面的链接所示。

<grid:GridControl x:Name="BasketSearchBasketGrid" ItemsSource="{Binding Path=Baskets}" ToolTip="Double click to show details.">
    <grid:GridControl.InputBindings>
        <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=SelectRowCmd}"/>
    </grid:GridControl.InputBindings>
    <grid:GridControl.View>
        <grid:TableView x:Name="view" AllowPerPixelScrolling="True" AutoWidth="True" NewItemRowPosition="None"
                            DetailHeaderContent="Search Results"
                            NavigationStyle="Row"
                            ShowFixedTotalSummary="False"
                            ShowGroupPanel="True"
                            ShowGroupedColumns="True"
                            ShowAutoFilterRow="false"
                            FadeSelectionOnLostFocus="False"
                            ShowIndicator="False"
                            BestFitMode="AllRows">
            <i:Interaction.Behaviors>
                <!-- We could use SelectedRow, however, to keep things consistent with the way child rows work, use this
                instead. -->
                <devExpressBehaviour:MasterFocusedRowBehavior FocusedRow="{Binding SelectedBasket, Mode=TwoWay}" />
            </i:Interaction.Behaviors>
        </grid:TableView>
    </grid:GridControl.View>
    <grid:GridControl.Columns>
        <grid:GridColumn Header="Basket Name" FieldName="BasketName" MinWidth="60"/>
        <grid:GridColumn Header="BasketStyle" FieldName="BasketStyle" MinWidth="40"/>
    </grid:GridControl.Columns>
    <grid:GridControl.DetailDescriptor>
        <dxg:DataControlDetailDescriptor ItemsSourcePath="Orders" ShowHeader="False">
            <grid:GridControl x:Name="BasketSearchOrderGrid" Tag="orderDetails"                                                      
                    >
                    <grid:GridControl.Columns>
                        <grid:GridColumn Header="Side" FieldName="Side" MinWidth="20"/>
                        <!-- More columns here -->
                    </grid:GridControl.Columns>
                    <grid:GridControl.View>
                    <dxg:TableView ShowGroupPanel="False">
                        <i:Interaction.Behaviors>
                            <!-- DevExpress does not support SelectedRow on a child grid. Use this custom behavior instead. -->
                            <devExpressBehaviour:DetailFocusedRowBehavior FocusedRow="{Binding SelectedOrder, Mode=TwoWay}" />
                        </i:Interaction.Behaviors>
                    </dxg:TableView>
                </grid:GridControl.View>
                </grid:GridControl>
        </dxg:DataControlDetailDescriptor>
    </grid:GridControl.DetailDescriptor>
</grid:GridControl>

关键是这些行,在<TableView>子网格的选项卡内。SelectedItem这些有效地用实际工作的附加属性替换了跟踪所选项目(即)的非工作方法。

<i:Interaction.Behaviors>
    <!-- DevExpress does not support SelectedRow on a child grid. Use this custom behavior instead. -->
    <devExpressBehaviour:DetailFocusedRowBehavior FocusedRow="{Binding SelectedOrder, Mode=TwoWay}" />
</i:Interaction.Behaviors>

请 DevExpress,让我们轻松一点,这应该可以!

于 2015-05-21T09:53:34.157 回答