注意:此条目的类型为“分享您的知识,Q& A Style”。我在下面回答我自己的问题。
不幸的是,在具有Master-Detail的DevExpress网格中,SelectedItem
对子网格不起作用。
如何计算子网格中选择的项目?
答案 0 :(得分:1)
请注意,从版本15.1开始,此方法过时,其中开箱即用支持绑定主网格和详细网格选择的功能。从该版本开始,直接绑定CurrentItem / SelectedItem / SelectedItems属性,如Master-detail grid - Add the capability to bind selection and navigation properties所述。
master-detail网格的以下属性现在支持绑定:
SelectedItem
,CurrentItem
,SelectedItems
。指定DataControlDetailDescriptor.ParentPath
属性或处理DataControlDetailDescriptor.CustomGetParent
事件以启用从ViewModel到网格的绑定。
答案 1 :(得分:0)
注意:此条目的类型为“分享您的知识,Q& A Style”。我在上面回答了我自己的问题。
经过一段时间的努力,我发现解决这个问题的最好方法是根据这些说明创建自己的附属属性:
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,让我们轻松,这应该工作!