我需要在另一個數據網格內顯示一個數據網格。我通過使用RowDetailsTemplate並在其中添加了一個數據網格來完成此操作。但主要問題是,我需要同時顯示多個內部網格。當選擇的項目更改時,不會顯示上一個選定項目的內部數據網格。任何建議:(Datagrid在另一個數據網格內
我使用展開控件顯示/隱藏的細節。當膨脹機控制打開時,我改變了RowDetailstemplate的可視性爲true。
當選定項目發生變化,當前的RowDetailsTemplate如果我展開擴展選定行只可見。
我需要在另一個數據網格內顯示一個數據網格。我通過使用RowDetailsTemplate並在其中添加了一個數據網格來完成此操作。但主要問題是,我需要同時顯示多個內部網格。當選擇的項目更改時,不會顯示上一個選定項目的內部數據網格。任何建議:(Datagrid在另一個數據網格內
我使用展開控件顯示/隱藏的細節。當膨脹機控制打開時,我改變了RowDetailstemplate的可視性爲true。
當選定項目發生變化,當前的RowDetailsTemplate如果我展開擴展選定行只可見。
找到了答案,
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;
}
您可以控制使用DataGridRow.DetailsVisibility
財產各行的行細節的可見度。
也許你還需要更改DataGrid.RowDetailsVisibilityMode
比另一個值210