Resizing columns with a star width column

1 Answer 198 Views
GridView
Thoerle
Top achievements
Rank 1
Thoerle asked on 05 May 2023, 10:51 AM

I have the following XAML

 


<Window x:Class="WpfApp46.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp46"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="1200"
        DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
        <telerik:RadGridView ItemsSource="{Binding Foos}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo1}" MinWidth="100" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo2}" MinWidth="100" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo3}" Width="*" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo4}" MinWidth="100" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo5}" MinWidth="100" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Foo6}" MinWidth="100" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>

and the following code behind

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp46
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public List<Foo> Foos { get; set; }

        public MainWindow()
        {
            Foos = new List<Foo>()
            {
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
                new Foo() { Foo1 = "Foo 1", Foo2 = "Foo 2", Foo3 = "Foo 3", Foo4 = "Foo 4", Foo5 = "Foo 5", Foo6 = "Foo 6" },
            };

            InitializeComponent();
        }
    }

    public class Foo
    {
        public string Foo1 { get; set; }
        public string Foo2 { get; set; }
        public string Foo3 { get; set; }
        public string Foo4 { get; set; }
        public string Foo5 { get; set; }
        public string Foo6 { get; set; }
    }
}
why can't I resize the columns "Foo5" and "Foo6"?

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 10 May 2023, 09:43 AM

Hello Lori,

Thank you for the shared code snippet. 

With the provided setup the columns Foo1, Foo2, Foo4, Foo5 and Foo6 will take their specified MinWidth of 100 and the Foo3 column will take the rest of the space available for the RadGridView.

The algorithm for resizing the columns in the RadGridView has different logic for positive and negative resizes. When you try to increase the size of a column, it first recalculates the widths of * sized columns then it recalculates the widths of non star sized columns starting from the last one to the resized one. When you try to decrease the size of a column, it recalculates non star columns first starting from the resized one to the last column and then recalculates * columns. Note, that this is a general summary and the logic is pretty complex as there are a lot of different scenarios to be covered. 

You will not be able to reduce the size of Foo1 and Foo2, since they cannot fall below their MinWidth. Their width can be increased though, since the increase in the Width of Foo1/Foo2 comes from the expense of Foo3 (with * Width). As for Foo5/Foo6 their width also cannot be decreased for the same reason (it cannot fall below their MinWidth) and their width cannot be increased since there isn't a column on their right, which can be decreased in width. 

I hope that I was able to shed some light on the column resizing logic of the RadGridView. 

Regards,
Vladimir Stoyanov
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.

Thoerle
Top achievements
Rank 1
commented on 10 May 2023, 01:36 PM

Thanks for the explanation.

I would have assumed that if there isn't a column that can shrink to the right, it would start looking to the left and pick up "Foo3" column to decrease it's size.

Is there a way to implement this desired behaviour, so instead of looking only to the right as a fallback look to the left?

Notice that the default DataGrid of WPF allows the increase of column Foo5 and Foo6, after increasing Foo4.

Vladimir Stoyanov
Telerik team
commented on 15 May 2023, 12:31 PM

There isn't a way to allow for the resizing of the Foo4/Foo5 columns with the exact setup of the columns shared in your first post.

What I can suggest in order to achieve this and keep as close as possible to the original setup is to change the Width of the last column to *. 

Thoerle
Top achievements
Rank 1
commented on 16 May 2023, 10:16 AM

The suggestion was rather obvious from the given explanation BUT it has a mayor down side, as it destroys the initial layout of the grid.

I could - maybe - overcome this limitation by giving Foo3 a width of `Width="9999*"` and Foo6 only a Width of `1*` as to mimic the desired auto width of Foo6, though it won't work when a cell value in Foo6 is larger then 1* and the cell value will be cut of, there for the suggestion isn't helping, as it destroys a fundumental feature of the Foo6 - auto width.

Therefor any other suggestions, maybe some developer feedback, why this shortcoming of the grid is a necessity?!?

I have to say, I am kind of disappointed to see you ignoring the fact the default datagrid is able to produce a better result, since IMHO a 3rd party vendor should strife to make a better product in every regard than the default - and resizing columns is such a basic feature of a grid, I am shocked, there for please don't ignore things I am saying/pointing out.

Vladimir Stoyanov
Telerik team
commented on 17 May 2023, 02:19 PM

I investigated possible alternatives for achieving the described behavior, however I am afraid that I cannot suggest a viable one as the column resizing logic is internal to the control. 

That said, I do agree that the column resizing behavior of the RadGridView in this scenario can be improved to resemble the DataGrid one.

I have logged the following item in our feedback portal: GridView: Improve column resizing to allow for columns on the right of a * sized column to be resized for this scenario. I have also added some telerik points to your account as a small thank you for your feedback. 

Thoerle
Top achievements
Rank 1
commented on 23 May 2023, 09:44 AM

To bad that there is no alternative.

Thanks for creating the item in your feedback portal, though I must say I don't agree with the category it was created with as I simply see the severity of the issue higher and wouldn't call it a "Feature Request" but a fixing a "Broken Feature". "Broken" because resizing the columns is simply impossible with the current setup.

I don't have an experience with the feedback portal, therefor I would like to ask if you can give a vague timeframe, is it a matter of hours/days/weeks/months/years - I could see a result from this feedback, so it is feasible to simply wait for it to complete or should I definitly go ahead with a workaround for the time being.

Martin Ivanov
Telerik team
commented on 26 May 2023, 08:25 AM

Usually we can't promise a specific time frame for implementing a feature. It is up to several different factors - like votes in the feedback portal, the internal priority of the feature relative to other features, the complexity and more. What I can suggest is to follow the feedback item in order to get notified as soon as its status changes.
Tags
GridView
Asked by
Thoerle
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or