Wpf Flexgrid Select and autoresizerows issues

Posted by: david on 6 July 2025, 4:58 am EST

  • Posted 6 July 2025, 4:58 am EST

    Hi

    I am facing following 2 issues in WPF Flexgrid.( Attached Sample project )

    1. flexGrid.Select(2, nCoulumns-1, true) this selects the cell but does not brings into the view. Tried ScrollIntoView as well without any luck.

    2. Facing a problem with AutoSizeRows. When I change the text the cell height grows, but when I reduce the text, the row height does not shrinks.

      In the project try to check/uncheck the checkbox to reproduce the issue.

    ImageConditional.zipImageConditional.zip

  • Posted 7 July 2025, 6:25 am EST

    Hi david,

    Thanks for reaching out to us.

    1. You need to Select the desired select after the grid is loaded, to bring it into view. Therefore, you can handle FlexGrid’s Loaded event as show below to achieve the desired behavior:

    private void flexGrid_Loaded(object sender, RoutedEventArgs e)
    {
        flexGrid.Select(2, nCoulumns - 1, true);
    }

    Kindly refer ImageConditional_Mod.zip to see the updates.

    1. We could replicate the issue on our end. We are currently discussing it with our developers. [Internal Tracking ID: C1XAML-38368]

    We will update you on this as soon as we hear back from them.

    Thanks & regards,

    Aastha

  • Posted 7 July 2025, 6:55 am EST

    1. But if you reload data after clearing all the rows, load event is not fired. Is there any other way?
  • Posted 8 July 2025, 6:43 am EST

    Hi David,

    For this requirement, you can handle FlexGrid.Rows’ CollectionChanged event as shown in the following code snippet:

    flexGrid.Rows.CollectionChanged += (s, e) =>
    {
        flexGrid.Select(2, nCoulumns - 1, true);
    };

    Kindly refer to the attached sample for full implementation. See ImageConditional_Mod2.zip

    Thanks & regards,

    Aastha

  • Posted 9 July 2025, 7:37 am EST

    It fires for each row added, not efficient way. I tried with beginInvoke like

    Dispatcher.BeginInvoke(New Action(Sub()

    GrdTests.Select(8, GrdTests.Columns.Count - 1, True)

    GrdTests.ScrollIntoView(0, GrdTests.Columns.Count - 1)

    End Sub), DispatcherPriority.ContextIdle)

    It scrolls almost to end but fall short of couple of columns

  • Posted 10 July 2025, 2:48 am EST - Updated 10 July 2025, 2:54 am EST

    Hi David,

    In the sample application that you provided earlier, we noticed that it adds unbound rows to the grid. In such cases, handling the FlexGrid.Rows.CollectionChanged event is the only way to automatically detect when data is reloaded after clearing the rows.

    The Dispatcher.CurrentDispatcher.BeginInvoke(…) approach is a manual instruction that tells the UI to run some code after it finishes rendering. It doesn’t run automatically, you have to call it yourself.

    We updated your sample to include this approach right after clearing the rows. However, we didn’t see the issue you mentioned about the issue of “falling short of couple of columns”. Please refer to the GIF below to see how it behaves on our end:

    We have also attached the modified sample for your reference: ImageConditional_Modified.zip

    Could you please update the attached sample to reproduce the issue and share a GIF/video showing what happens on your side? Also, please let us know what exact behavior you’re trying to achieve.

    Thanks for your cooperation.

    Kind Regards,

    Aastha

  • Posted 10 July 2025, 7:51 am EST

    Hi Aastha

    Basically scrolling sucks up the flexgrid. Even if I use the above changes, the grid freezes for while and sometimes show blank space near the scrollbars. The problem is scrolling, as it tries to build the cells using factory.

  • Posted 11 July 2025, 5:43 am EST

    Hi David,

    We understand your frustration. Could you please provide a stripped-down version of your sample application so that we can replicate the issue on our end? This will help us investigate the issue more closely and provide you with a more accurate solution.

    Thanks & regards,

    Aastha

  • Posted 14 July 2025, 12:34 am EST

    Hi Aastha

    Not frustrated yet, still have “aastha” you will get it done, It’s difficult for me to get sample to show the issue. I will try to get it soon.

    Thanks

    David

  • Posted 14 July 2025, 5:13 am EST

    Hi David,

    Thank you for keeping things positive😊 I really appreciate the clever wordplay!

    Please take your time with the sample. I’ll be here to assist you once it’s ready.

    Thanks & regards,

    Aastha

  • Posted 10 August 2025, 7:51 am EST

    “We could replicate the issue on our end. We are currently discussing it with our developers. [Internal Tracking ID: C1XAML-38368]”

    Is there any Update on this issue?

  • Posted 10 August 2025, 10:02 pm EST

    Hi David,

    The developers mentioned that this issue occurs because the cell is using a CellTemplate, and when the Text property of the TextBlock inside the template is updated, the cell’s IsMeasureValid property does not set to false.

    As a workaround, they suggest invalidating the measure of both the Grid and the GridCellView after updating the text. Here’s the code snippet they provided:

    public override void BindCellContent(GridCellType cellType, GridCellRange range, FrameworkElement cellContent)
     {
         if (cellType == GridCellType.Cell && range.Column > 0)
         {
              //show text for cells
              var textBlock = (cellContent as Grid).Children[0] as TextBlock;
              var cellValue = Grid[range.Row, range.Column];
                 textBlock.Text = cellValue?.ToString() + "";
             cellContent.InvalidateMeasure();
             (cellContent.Parent as FrameworkElement).InvalidateMeasure();
         }
         base.BindCellContent(cellType, range, cellContent);
     }

    Kindly refer to the attached sample for full implementation. See ImageConditional1.zip

    Thanks & regards,

    Aastha

  • Posted 14 August 2025, 3:22 am EST

    Thanks Aastha

    But I am still struggling with the same issue. Here is the project for your team to debug.

    Just Toggle the “Show Additional remarks” toolbar button to reproduce the issue

  • Posted 14 August 2025, 3:23 am EST

    Forgot to attach the file, Here it goes…ImageConditional.zip

  • Posted 17 August 2025, 8:20 am EST

    Hi David,

    Thanks for sharing the sample application.

    We are currently discussing it with our developers. We will update you soon on this.

    Thanks & regards,

    Aastha

Need extra support?

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

Learn More

Forum Channels