我被困在这里,我如何在devexpress网格控件上使用嵌套网格。我研究了很多但是找不到任何好的东西。这是我的
XAML
<dxdo:LayoutPanel Caption="Photography Jobs" AllowClose="False" Name="pnlShotoJobs" GotFocus="pnlShotoJobs_GotFocus">
<my:GridControl Name="dgPhotoJobs" MouseDoubleClick="dgPhotoJobs_MouseDoubleClick">
<my:GridControl.Columns>
<my:GridColumn FieldName="JobName" Name="grdColumnJobName" />
<my:GridColumn FieldName="JobDate" Name="grdColumnJobDate" />
</my:GridControl.Columns>
<my:GridControl.View>
<my:TableView NavigationStyle="Row" ShowAutoFilterRow="True" ShowGroupPanel="False" MultiSelectMode="Row" Name="JobTableView" MouseUp="JobTableView_MouseUp" AllowEditing="False" Focusable="False">
</my:TableView>
</my:GridControl.View>
</my:GridControl>
</dxdo:LayoutPanel>
设计
当我们点击任何Photography Jobs
时,新网格将在该被点击的行下方打开,并拥有属于所点击行的主键ID的所有数据。
如果您有任何代码或任何建议,请与我分享。
提前致谢。
答案 0 :(得分:3)
要显示GridControl行的嵌套网格,请定义DataRowTemplate。像这样:
<my:GridControl Name="dgPhotoJobs" MouseDoubleClick="dgPhotoJobs_MouseDoubleClick">
<my:GridControl.Columns>
<my:GridColumn FieldName="JobName" Name="grdColumnJobName" />
<my:GridColumn FieldName="JobDate" Name="grdColumnJobDate" />
</my:GridControl.Columns>
<my:GridControl.View>
<my:TableView NavigationStyle="Row" ShowAutoFilterRow="True" ShowGroupPanel="False" MultiSelectMode="Row" Name="JobTableView" AllowEditing="False" Focusable="False">
<dxg:TableView.DataRowTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<core:MeasurePixelSnapper>
<ContentPresenter ContentTemplate="{DynamicResource {dxgt:GridRowThemeKey ResourceKey=DataRowTemplate}}" Name="defaultRowPresenter" />
</core:MeasurePixelSnapper>
<core:DXExpander HorizontalExpand="None" IsExpanded="{Binding Path=(dxg:DataViewBase.IsFocusedRow), RelativeSource={RelativeSource TemplatedParent}}" VerticalExpand="FromTopToBottom">
<Border Background="Cyan" BorderBrush="{DynamicResource {dxgt:GridRowThemeKey ResourceKey=GridDataRowDelimiterBrush}}" BorderThickness="0,1,0,0" TextElement.Foreground="Black">
<Grid MaxHeight="400">
<dxg:GridControl Grid.Row="1" AutoPopulateColumns="False" ItemsSource="{Binding Path=DataContext.MyCollection, UpdateSourceTrigger=PropertyChanged}" >
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Column1" FieldName="FieldName1" AllowEditing="False"/>
<dxg:GridColumn Header="Column2" FieldName="FieldName2" AllowEditing="False">
</dxg:GridControl.Columns>
</dxg:GridControl>
</Grid>
</Border>
</core:DXExpander>
</StackPanel>
</DataTemplate>
</dxg:TableView.DataRowTemplate>
</my:TableView>
</my:GridControl.View>
</my:GridControl>
这是我的xml名称空间:
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys" xmlns:core="http://schemas.devexpress.com/winfx/2008/xaml/core"