This is a migrated thread and some comments may be shown as answers.

Disposal the RadGridView's column width resize bug!

5 Answers 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
wu
Top achievements
Rank 1
Veteran
wu asked on 12 Oct 2018, 07:11 AM

if before the fixed width  column,there is the "*" column,for example:
  there are five columns,column0=150;column1=*;column2=250;column3=150;column4=250;
It is difficult resize the column width,I search the feedback information,and found there is the feedback in 2016,
but don't disposal ,so i got the old source code,and find some question code :
   in the GridViewColumnCollectionInternal.cs file,the function RecalculateNonStarColumnWidthsOnPositiveResize()
and RecalculateNonStarColumnWidthsOnNegativeResize() have bug.
    the first: adjust the RecalculateNonStarColumnWidthsOnPositiveResize()
change frome
column.SetWidthInternal(new GridViewLength(width.Value, GridViewLengthUnitType.Pixel, width.DesiredValue, width.DisplayValue - columnExcessWidth));
to
  column.SetWidthInternal(new GridViewLength(width.DisplayValue - columnExcessWidth));

then positive resize is OK!
In addition,the other method:
//PositiveResize Non * column
private double RecalculateNonStarColumnWidthsOnPositiveResize(
   double change,
   int index,
   bool retainAuto)
  {
   if (DoubleUtil.GreaterThan(change, 0.0))
   {
                #region calculate the resize total width
                double canAdjustWidth = 0;double totalWidth = 0;
                for (int i = this.Count - 1;  i > index; i--)
                {
                    var column = this.ColumnFromDisplayIndex(i);
                    if (!IsColumnResizable(column))
                    {
                        continue;
                    }
                    var width = column.Width;
                    var minWidth = column.MinWidth;
                    if (!width.IsStar &&
                        DoubleUtil.GreaterThan(width.DisplayValue, minWidth))
                    {
                        canAdjustWidth += width.DisplayValue - minWidth;
                        totalWidth += width.DisplayValue;
                    }
                }
                #endregion
                #region resize column by scale
                double actualAdjustWidth = 0;
                if (change > canAdjustWidth) actualAdjustWidth = canAdjustWidth;
                else actualAdjustWidth = change;
                for (int i = this.Count - 1; i > index; i--)
                {
                    var column = this.ColumnFromDisplayIndex(i);
                    if (!IsColumnResizable(column))
                    {
                        continue;
                    }
                    var width = column.Width;
                    var minWidth = column.MinWidth;
                    if (!width.IsStar &&
                        DoubleUtil.GreaterThan(width.DisplayValue, minWidth))
                    {
                        double adj = width.DisplayValue* actualAdjustWidth / totalWidth;
                        column.SetWidthInternal(new GridViewLength(width.DisplayValue-adj));
                    }
                }
                #endregion
                #region adjust the current column
                if (DoubleUtil.GreaterThan(actualAdjustWidth, 0.0))
                {
                    var column = this.ColumnFromDisplayIndex(index);
                    SetColumnWidth(column, actualAdjustWidth, retainAuto);
                    change -= actualAdjustWidth;
                }
                #endregion
   }
   return change;
  }
 and second modify the NegativeResize code:
  private double RecalculateNonStarColumnWidthsOnNegativeResize(
   double change,
   int index,
   bool retainAuto)
  {
   if (DoubleUtil.GreaterThan(change, 0.0))
   {
                #region calculate the total width of the right resize column
                double canAdjustWidth = 0;
                int needAdjustCount = 0;
                int needAdjustCountStar = 0;
                bool isExistMinWidth = false;
                for (int i = index + 1;  i < this.Count; i++)
                {
                    var column = this.ColumnFromDisplayIndex(i);
                    if (!IsColumnResizable(column))
                    {
                        continue;
                    }
                    var width = column.Width;
                    //include the * column
                    if (!DoubleUtil.AreClose(width.DisplayValue, column.MaxWidth))
                    {
                        canAdjustWidth += width.DisplayValue;
                        if (!width.IsStar) //fixed column
                        {
                            needAdjustCount += 1;
                            if (DoubleUtil.GreaterThan(column.MinWidth*3, width.DisplayValue))
                            {
                                isExistMinWidth = true;
                            }
                        }
                        else
                            needAdjustCountStar += 1;
                    }
                }
                #endregion
                #region  when the fixed column width is small the  three times minvalue,or non * column
                if(!isExistMinWidth && needAdjustCountStar>0) return change;
                #endregion
                #region resize column by scale
                double actualAdjustWidth = 0;
                double totalAdjustWidth = 0;
                if (change > canAdjustWidth)
                    actualAdjustWidth = canAdjustWidth;
                else
                    actualAdjustWidth = change;
                for (int i = this.Count - 1; i > index; i--)
                {
                    var column = this.ColumnFromDisplayIndex(i);
                    if (!IsColumnResizable(column))
                    {
                        continue;
                    }
                    var width = column.Width;
                    if (!width.IsStar &&
                        !DoubleUtil.AreClose(width.DisplayValue, column.MaxWidth))
                    {
                        double adj = width.DisplayValue * actualAdjustWidth / canAdjustWidth;
                        totalAdjustWidth += adj;
                        column.SetWidthInternal(new GridViewLength(width.DisplayValue + adj));
                    }
                }
                #endregion
                #region adjust the current column
                if (DoubleUtil.GreaterThan(totalAdjustWidth, 0.0))
                {
                    var column = this.ColumnFromDisplayIndex(index);
                    SetColumnWidth(column, -totalAdjustWidth, retainAuto);
                    change -= totalAdjustWidth;
                }
                #endregion          
   }
   return change;
  }


5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Oct 2018, 03:50 PM
Hello Wu,

Can you please clarify whether you refer to this forum post? I am afraid, that for the time being the demonstrated usage of the ColumnWidthChanging event is the only solution we can provide.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
wu
Top achievements
Rank 1
Veteran
answered on 16 Oct 2018, 11:20 PM

No,because there is the bug(many years):

for example:if there are five columns,column0 width=150;column1 width=*;column2 width=250;column3 width=150;column4 width=250;It is difficult resize the column width,when resize the column2 width by mouse,the column show flash!

    so I check out the old source code ,the above code can resolve the bug.

0
Stefan
Telerik team
answered on 19 Oct 2018, 01:30 PM
Hi Wu,

Thanks for the update.

I am not able to replicate such an issue with the latest assemblies version. Attached to my reply you can find a sample application that demonstrates this. Can you please check it out? Would it be possible for you to try the behavior of the control on your end with the latest binaries? Is the issue still reproduced with them?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
wu
Top achievements
Rank 1
Veteran
answered on 19 Oct 2018, 02:24 PM

look my feedback:

https://feedback.telerik.com/Project/143/Feedback/Details/243686-gridview-column-resize-problem

there is still the problem in the V2018 R3 SP1.

the radgridview demo name is 'Totals',when you try adjust the column 'Unit Price' ,you will find the column grow or lessen suddenly,only when the 'star' column is located in the fix column's left,there are some problem!

 

0
Vladimir Stoyanov
Telerik team
answered on 24 Oct 2018, 01:03 PM
Hello Wu,

Thank you for the clarification. 

I investigated the described scenario in detail and I was able to reproduce the described scenario on my end. This is why I have logged a new item in our feedback portal for this behavior: 
GridView: Incorrect resizing of columns when there is a column with star("*") width between two fixed width columns.

I have also included all of the information from this thread in the internal item, so that it can be taken into account during development. As a small token of gratitude for bringing this to our attention, I have awarded you with some telerik points

I am afraid that currently I cannot suggest another workaround for this behavior other than the already suggested in the referenced forum thread.

Regards,
Vladimir Stoyanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
wu
Top achievements
Rank 1
Veteran
Answers by
Stefan
Telerik team
wu
Top achievements
Rank 1
Veteran
Vladimir Stoyanov
Telerik team
Share this question
or