2012-03-22 50 views
0

我需要在另一个数据网格内显示一个数据网格。我通过使用RowDetailsTemplate并在其中添加了一个数据网格来完成此操作。但主要问题是,我需要同时显示多个内部网格。当选择的项目更改时,不会显示上一个选定项目的内部数据网格。任何建议:(Datagrid在另一个数据网格内

我使用展开控件显示/隐藏的细节。当膨胀机控制打开时,我改变了RowDetailstemplate的可视性为true。

当选定项目发生变化,当前的RowDetailsTemplate如果我展开扩展选定行只可见。

回答

0

找到了答案,

private void Expander_Expanded(object sender, RoutedEventArgs e) 
    { 
    int rowIndex = this.DataGridForEvents.SelectedIndex; 
    List<DataGridRow> rows = GetRows(); 
    rows[rowIndex].DetailsVisibility = Visibility.Visible; 
    } 

private void Expander_Collapsed(object sender, RoutedEventArgs e) 
{ 
int rowIndex = this.DataGridForEvents.SelectedIndex; 
List<DataGridRow> rows = GetRows(); 
rows[rowIndex].DetailsVisibility = Visibility.Collapsed; 
} 



public List<DataGridRow> GetRows() 
{ 
List<DataGridRow> rows = new List<DataGridRow>(); 
foreach (var rowItem in this.DataGridForEvents.ItemsSource) 
{ 
this.DataGridForEvents.ScrollIntoView(rowItem, this.DataGridForEvents.Columns.Last()); 
FrameworkElement el = this.DataGridForEvents.Columns.Last().GetCellContent(rowItem); 
DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement); 
if (row != null) 
rows.Add(row); 
} 
return rows; 
} 
相关问题