|
this.datagrid.FilterChanging += datagrid_FilterChanging;
List<int> selectedIndex = new List<int>();
void datagrid_FilterChanging(object sender, GridFilterEventArgs e)
{
if (this.datagrid.SelectedItems.Count > 0)
{
foreach (var item in this.datagrid.SelectedItems)
{
//You can get the SelectedIndex here.
selectedIndex.Add(this.datagrid.ResolveToRowIndex(item as OrderInfo));
}
}
} |
Hi Gnanasownthari,
thank you for the answer, unfortunately it does not address my problem. I am able to maintain the list of selected rows using SelectionController.SelectedRows.Select(x => x.RowIndex). This gives me the list of the selected rows based on the filtered view. Howver, SelectedRows() uses the provided parameters startRows and endRows ans selected based on the ItemsSource although the list is still filtered. Despite the question if it makes sens to reapply a filter after reloading data just based on row numbers this seems to be wrong. Let me describe an example:
There is a list
I do now select row 1 and calculate the selected entries by accumulating all children, i.e. 2
Then I filter for column 1 = "b" My display is now:
|
//Maintain CaptionsummaryText
List<object> captionSummaryRowText = new List<object>();
//Maintain the selected DataRowIndex
List<int> dataRowIndex = new List<int>();
//Maintain SelectedIndex
List<int> selectedIndex = new List<int>();
private void Button_Click(object sender, RoutedEventArgs e)
{
selectedIndex = this.datagrid.SelectionController.SelectedRows.Select(x => x.RowIndex).ToList();
foreach (int index in selectedIndex)
{
var captionSumaryRowControl = this.datagrid.RowGenerator.Items.Find(x => x.Index == index);
if (!(captionSumaryRowControl is DataRow))
{
//Add the selected CaptionSumarryRow
var captionRowText = (captionSumaryRowControl.RowData as Group).Key;
captionSummaryRowText.Add(captionRowText);
}
else
{
//Add the selected DataRow
if (index <= this.datagrid.View.Records.Count)
{
var dataRow = this.datagrid.View.Records.ElementAt(index - 1).Data;
dataRowIndex.Add(viewModel.OrderInfoCollection.IndexOf(dataRow));
}
}
}
}
private void Button_Click1(object sender, RoutedEventArgs e)
{
var captionRows=this.datagrid.RowGenerator.Items.Where(x => x.RowType == RowType.CaptionCoveredRow);
var dataRows = this.datagrid.RowGenerator.Items.Where(x => x.RowType == RowType.DefaultRow);
foreach (int index in dataRowIndex)
{
if (index < viewModel.OrderInfoCollection.Count)
{
foreach (var dataRow in dataRows)
{
if (dataRow.RowData == viewModel.OrderInfoCollection.ElementAt(index))
{
//Reapply the selection for DataRow
this.datagrid.SelectedItems.Add(dataRow.RowData);
break;
}
}
}
}
foreach (object captionRowText in captionSummaryRowText)
{
foreach (var captionRow in captionRows)
{
if (captionRowText.ToString() == (captionRow.RowData as Group).Key.ToString())
{
//Reapply the selection for CaptionSumarryRow
this.datagrid.SelectionController.SelectRows(captionRow.RowIndex, captionRow.RowIndex);
break;
}
}
}
} |