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;
}