Posted 28 March 2023, 8:36 pm EST
In C1DataGrid, we are using CollectionViewSource for Grouping.
If any group element or row is selected, is there any way to highlight its respective Parent row?
Thank you…
Forums Home / ComponentOne / WPF Edition
Posted by: mayur.purandare on 28 March 2023, 8:36 pm EST
Posted 28 March 2023, 8:36 pm EST
In C1DataGrid, we are using CollectionViewSource for Grouping.
If any group element or row is selected, is there any way to highlight its respective Parent row?
Thank you…
Posted 29 March 2023, 9:14 pm EST
Hi Mayur,
Thanks for reaching out to us.
You can achieve this requirement by handling the SelectionChanged event as:
private void SelectionChanged(object sender, C1.WPF.DataGrid.DataGridSelectionChangedEventArgs e)
{
if (e.AddedRanges.Count > 0)
{
var index = e.AddedRanges.First().Rows.First().Index;
for (int i = index; i >= 0; i--)
{
if (grid.Rows[i] is DataGridGroupRow)
{
grid.Rows[i].Presenter.Background = Brushes.Red;
break;
}
}
}
if(e.RemovedRanges.Count > 0)
{
var index2 = e.RemovedRanges.First().Rows.First().Index;
for (int i = index2; i >= 0; i--)
{
if (grid.Rows[i] is DataGridGroupRow)
{
grid.Rows[i].Presenter.Background = null;
break;
}
}
}
}
Please refer the attached sample for the same: DataGridGroupFormat.zip
Best Regards,
Nitin
Posted 2 April 2023, 9:07 pm EST
Hello Nitin,
Thank you for the answer.
We tried the same way as mentioned.
However, the row that I want to highlight is getting highlighted, but a couple of other rows are also getting highlighted.
More detail :
2.Alao tried giving it hard coded i.e., grid.Rows[1].Presenter.Background = Brushes.Red, just to check the behavior.
Posted 3 April 2023, 7:27 pm EST
Hi,
We are unable to replicate this issue at our end. Could you please provide a stripped-down sample or replication steps for our sample to replicate this behavior at our end. So, that we can assist you accordingly. Also, Xaml code that you have provided is empty.
We have updated the sample to achieve this requirement. Now we can Highlight respective ParentGroup and SubGroups. DataGridGroupFormat_Mod.zip
Best Regards,
Nitin
Posted 4 April 2023, 3:29 pm EST
Hello,
Thank you for the reply.
Sharing a sample application with the mentioned issue replicated.DGRow-ComponentOne Query.zip
Posted 4 April 2023, 6:03 pm EST
Hi Mayur,
Thanks for the sample.
We have replicated this issue at our end. This can be solved by handling LoaderRowPresenter and UnloadedRowPresenter as:(see code snippet)
private void Grid_UnloadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
{
if (e.Row is DataGridGroupRow grp)
grp.Presenter.Background = null;
}
private void Grid_LoadedRowPresenter(object sender, C1.WPF.DataGrid.DataGridRowEventArgs e)
{
if (grid.Selection.SelectedRows.Count > 0)
if (e.Row is DataGridGroupRow grp)
if(grp.Rows.Any(x => x.DataItem == grid.Selection.SelectedRows[0].DataItem))
UpdateCurrentGroupBackground(e.Row.Index, Brushes.Red);
}
Please refer the attached modified sample for the same: DataGridGroupFormat_Mod2.zip
Best Regards,
Nitin