How to set row height programatically like in WinForms?

1 Answer 93 Views
VirtualGrid
Hanjo
Top achievements
Rank 1
Hanjo asked on 06 Feb 2024, 09:08 AM

Hello,

 

I found row-height setting API in WinForms, like Resizing Rows Programmatically- RadVirtualGrid - Telerik UI for WinForms .

But can't find it for WPF. I can make rows resizable by a user but can't do it programatically.

What I'd like to do is to control row height per cell content height.

 

Thanks.

Hanjo

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Feb 2024, 10:05 AM

Hello Hanjo,

Currently, the rows can be resized from the UI or you can set the height of all rows. More information is available here: WPF VirtualGrid - Column and Row Resizing. 

We have a feature request for functionality that will fit your case: VirtualGrid: Provide an option to fit the row height to content

I am afraid I cannot suggest a workaround.

I want to apologize for the inconvenience this is causing you.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Kenneth
Top achievements
Rank 1
commented on 23 Jun 2025, 10:23 AM

When do you think this will be available, or is there any way to access the row height via reflection or similar.

/Kenneth
Dimitar
Telerik team
commented on 24 Jun 2025, 06:13 AM

Hi Kenneth, 

I am afraid this is still not scheduled for implementation. I can not provide a timeframe for the implementation of this feature. 

I was able to find a way to access this with reflection. Here is the method: 

private void RadVirtualGrid_Loaded(object sender, RoutedEventArgs e)
{
    var panel = this.radVirtualGrid.ChildrenOfType<VirtualizingCanvasBase>().FirstOrDefault();
    if (panel != null )
    {
        UpdateRowSizeByReflection(panel, 3, 200);
    }
    
}

public static void UpdateRowSizeByReflection(object panelInstance, int rowIndex, double newSize)
{
    if (panelInstance == null)
        throw new ArgumentNullException(nameof(panelInstance));

    // Get the type of the panel
    var panelType = panelInstance.GetType();

    // Find the UpdateElementSize method
    var method = panelType.GetMethod(
        "UpdateElementSize",
        System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);

    if (method == null)
        throw new InvalidOperationException("UpdateElementSize method not found.");

    // Find the VirtualGridOrientation enum type
    var orientationType = panelType.Assembly.GetType("Telerik.Windows.Controls.VirtualGrid.VirtualGridOrientation");
    if (orientationType == null)
        throw new InvalidOperationException("VirtualGridOrientation type not found.");

    // Get the Vertical enum value
    var verticalValue = Enum.Parse(orientationType, "Vertical");

    // Call the method: index = rowIndex, size = newSize, orientation = Vertical
    method.Invoke(panelInstance, new object[] { rowIndex, newSize, verticalValue });

    var updateUIMethod = panelType.GetMethod(
"UpdateUI",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);

    if (updateUIMethod == null)
        throw new InvalidOperationException("UpdateUI method not found.");

    updateUIMethod.Invoke(panelInstance, null);
}

Let me know if I can assist you further.

 

 

Tags
VirtualGrid
Asked by
Hanjo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or