2012-03-22 51 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; 
} 
相關問題