RadGridView: selecting a range of cells includes ones from hidden columns

1 Answer 93 Views
GridView
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Eldoir asked on 01 Jun 2022, 09:09 AM | edited on 01 Jun 2022, 09:11 AM

Hello,

I'm using a textbox where the user can type something, and my RadGridView only shows the relevant columns. For example if the user types "rad", I will only show columns containing "rad" in their header.

I just noticed when the columns are filtered out this way, and I select a range of cells, it also includes the cells from the hidden columns!

How to only include cells from visible columns in the range?

For example on this screenshot I selected the top left cell then hold Shift and selected the bottom right cell.

We see that 4 cells are selected, but actually much more got selected! (all the ones in the red box, so from "SourceRadius" to "Reach Radius" columns, because I guess internally you're using column indexes to select the range of cells?)

I must precise I'm using dynamically created columns, if it matters.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
answered on 03 Jun 2022, 02:41 PM | edited on 03 Jun 2022, 02:42 PM

Hello again,

I've finally answered my own question - I simply created a behavior that listens for SelectedCellsChanging, and removes the unwanted cells before they're carried out to the SelectedCellsChanged event.

Here is the code, the relevant line is in OnRadGridViewSelectedCellsChanging (uses System.Linq):

public class RemoveHiddenCellsFromSelectedCellsBehavior : Behavior<RadGridView>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.SelectedCellsChanging += OnRadGridViewSelectedCellsChanging;
    }

    protected override void OnDetaching()
    {
        AssociatedObject.SelectedCellsChanging -= OnRadGridViewSelectedCellsChanging;
        base.OnDetaching();
    }

    private void OnRadGridViewSelectedCellsChanging(object sender, GridViewSelectedCellsChangingEventArgs args)
    {
        AssociatedObject.SelectedCells.RemoveRange(args.AddedCells.Where(cell => !cell.Column.IsVisible));
    }
}
Cheers,
Arthur
Tags
GridView
Asked by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or