FlexGrid SelectionChanged Event Called Multiple Times When Removing Selection

Posted by: jared.fritsch on 6 December 2017, 10:02 am EST

    • Post Options:
    • Link

    Posted 6 December 2017, 10:02 am EST

    I am handling row selection of a FlexGrid like so:

    <grid:FlexGrid
        x:Name="Grid1"
        SelectionMode="Row"
        SelectionChanged="Grid1_OnSelectionChanged"
        AutoGenerateColumns="True" />
    

    What I need is the ability to deselect the row should a certain condition exist.

    private void Grid1_OnSelectionChanged(object sender, GridCellRangeEventArgs e)
    {
        if(MyCondition)
        {
            //((FlexGrid) sender).Selection = null;
    	((FlexGrid)sender).Select(new GridCellRange(-1, -1), false);
        }
    }
    

    What I would expect to happen is for this event to fire once when I click the row, and then fire again if my condition is true and I programatically deselect any row. In v2.4.20173.195 this worked as expected. As of v2.4.20173.222 and continuing on into v2.4.2017.234, this event fires four times. First for the range of the clicked row, then for the new row I programatically selected, then again for the clicked row, then again for the new row I programatically selected.

  • Posted 7 December 2017, 12:08 am EST

    I should mention that this is not working on UWP. I have not tested it on Android or iOS.

  • Posted 7 December 2017, 1:57 am EST

    Thanks, Jared. I’ll report this one as well. There’s a good chance it’s related to the issue you mentioned yesterday so hopefully both issues can be fixed together.

    Kelley

  • Posted 7 December 2017, 2:37 am EST

    Thanks Kelley. I figured they may be related.

  • Posted 14 December 2017, 7:43 am EST

    Hi Jared

    I mentioned the prerelease build in other threads so I’ll skip it here, but one other note on this case. The developers recommend that you use the SelectionChanging event rather than SelectionChanged for your use case. They recommend something like this:

     private void Grid_SelectionChanging(object sender, GridCellRangeEventArgs e)
            {
                if (e.CellRange.Row == 4)
                {
                    grid.Selection = new GridCellRange(-1, -1);
                    e.Cancel = true;
                }
            }
    
    

    Kelley

  • Posted 15 December 2017, 12:37 am EST

    Interesting - I will test this out and see if this works better for our case. Thanks!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels