Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor DataGridView.Methods to remove ArrayList usage #8650

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ private bool AdjustFillingColumns()
int imposedWidthSum = 0; // total width of columns that don't have a flexible width.
int requiredWidthSum = 0; // total of the minimum widths of the visible auto filled columns.
float weightSum = 0F; // total of the weights of the visible auto filled columns.
ArrayList autoFillColumns = null;
List<DataGridViewColumn> autoFillColumns = null;
foreach (DataGridViewColumn dataGridViewColumn in Columns)
{
if (dataGridViewColumn.Visible)
Expand All @@ -937,7 +937,7 @@ private bool AdjustFillingColumns()
numVisibleFillColumns++;
requiredWidthSum += dataGridViewColumn.DesiredMinimumWidth > 0 ? dataGridViewColumn.DesiredMinimumWidth : dataGridViewColumn.MinimumWidth;
weightSum += dataGridViewColumn.FillWeight;
autoFillColumns ??= new ArrayList(Columns.Count);
autoFillColumns ??= new(Columns.Count);

autoFillColumns.Add(dataGridViewColumn);
}
Expand Down Expand Up @@ -981,7 +981,7 @@ private bool AdjustFillingColumns()
availableWidth = 0;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
int minimumWidth = dataGridViewColumn.DesiredMinimumWidth > 0 ? dataGridViewColumn.DesiredMinimumWidth : dataGridViewColumn.MinimumWidth;
if (dataGridViewColumn.Thickness != minimumWidth)
{
Expand All @@ -997,7 +997,7 @@ private bool AdjustFillingColumns()
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
// Make sure the UsedFillWeight correspond to the actual column width
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.UsedFillWeight = dataGridViewColumn.Width * weightSum / availableWidth;
}

Expand All @@ -1020,7 +1020,7 @@ private bool AdjustFillingColumns()
bool desiredWidthTooSmall = false;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
if (columnEntry == autoFillColumns.Count - 1)
{
dataGridViewColumn.DesiredFillWidth = availableWidth - usedWidth;
Expand Down Expand Up @@ -1048,7 +1048,7 @@ private bool AdjustFillingColumns()
float weightSumNoneMinimal = weightSum;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
if (dataGridViewColumn.DesiredFillWidth == -1)
{
int minimumWidth = dataGridViewColumn.DesiredMinimumWidth > 0 ? dataGridViewColumn.DesiredMinimumWidth : dataGridViewColumn.MinimumWidth;
Expand All @@ -1060,7 +1060,7 @@ private bool AdjustFillingColumns()

for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
if (dataGridViewColumn.DesiredFillWidth != -1)
{
dataGridViewColumn.UsedFillWeight = dataGridViewColumn.FillWeight * usedWeightSumNoneMinimal / weightSumNoneMinimal;
Expand All @@ -1073,7 +1073,7 @@ private bool AdjustFillingColumns()
// Each UsedFillWeight simply equals the FillWeight
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.UsedFillWeight = dataGridViewColumn.FillWeight;
}
}
Expand All @@ -1091,7 +1091,7 @@ private bool AdjustFillingColumns()
// Allocate additional width according to UsedFillWeight and FillWeight values
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.DesiredFillWidth = dataGridViewColumn.Width;
}

Expand All @@ -1102,7 +1102,7 @@ private bool AdjustFillingColumns()
bool minimumColumnExists = false;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
fillWeightRatioSum += dataGridViewColumn.FillWeight / dataGridViewColumn.UsedFillWeight;
if (dataGridViewColumn.DesiredFillWidth <= dataGridViewColumn.MinimumWidth)
{
Expand All @@ -1112,7 +1112,7 @@ private bool AdjustFillingColumns()

for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
if (gain == 0)
{
floatDesiredWidths[columnEntry] = _availableWidthForFillColumns * dataGridViewColumn.UsedFillWeight / weightSum;
Expand All @@ -1131,7 +1131,7 @@ private bool AdjustFillingColumns()

for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.UsedFillWeight = weightSum / availableWidth * floatDesiredWidths[columnEntry];
}
}
Expand All @@ -1142,7 +1142,7 @@ private bool AdjustFillingColumns()
int cumulatedWidthLoss = 0;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.DesiredFillWidth = dataGridViewColumn.Width;
}

Expand All @@ -1161,7 +1161,7 @@ private bool AdjustFillingColumns()
DataGridViewColumn mostDeservingDataGridViewColumn = null;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
if (dataGridViewColumn.DesiredFillWidth > dataGridViewColumn.MinimumWidth)
{
fillWeightRatio = dataGridViewColumn.UsedFillWeight / dataGridViewColumn.FillWeight;
Expand All @@ -1177,9 +1177,9 @@ private bool AdjustFillingColumns()
if (mostDeservingDataGridViewColumn is not null)
{
float floatDesiredWidth = (stepDownAvailableWidthForFillColumns * mostDeservingDataGridViewColumn.UsedFillWeight / weightSum) - widthLoss * mostDeservingDataGridViewColumn.UsedFillWeight / mostDeservingDataGridViewColumn.FillWeight / fillWeightRatioSum;
if (floatDesiredWidth < (float)mostDeservingDataGridViewColumn.MinimumWidth)
if (floatDesiredWidth < mostDeservingDataGridViewColumn.MinimumWidth)
{
floatDesiredWidth = (int)mostDeservingDataGridViewColumn.MinimumWidth;
floatDesiredWidth = mostDeservingDataGridViewColumn.MinimumWidth;
}

int oldDesiredWidth = mostDeservingDataGridViewColumn.DesiredFillWidth;
Expand All @@ -1198,7 +1198,7 @@ private bool AdjustFillingColumns()
stepDownAvailableWidthForFillColumns -= oldDesiredWidth - mostDeservingDataGridViewColumn.DesiredFillWidth;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
dataGridViewColumn.UsedFillWeight = weightSum / stepDownAvailableWidthForFillColumns * dataGridViewColumn.DesiredFillWidth;
}
}
Expand All @@ -1218,7 +1218,7 @@ private bool AdjustFillingColumns()
float weightSumDbg = 0F;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
weightSumDbg += dataGridViewColumn.UsedFillWeight;
}

Expand All @@ -1236,7 +1236,7 @@ private bool AdjustFillingColumns()
DataGridViewColumn mostDeservingDataGridViewColumn = null;
if (autoFillColumns.Count == 1)
{
mostDeservingDataGridViewColumn = (DataGridViewColumn)autoFillColumns[0];
mostDeservingDataGridViewColumn = autoFillColumns[0];
mostDeservingDataGridViewColumn.DesiredFillWidth = Math.Max(availableWidth - usedWidth, mostDeservingDataGridViewColumn.MinimumWidth);
autoFillColumns.Clear();
}
Expand All @@ -1245,7 +1245,7 @@ private bool AdjustFillingColumns()
float biggestWeightDiscrepancy = 0F, weightDiscrepancy;
for (columnEntry = 0; columnEntry < autoFillColumns.Count; columnEntry++)
{
DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)autoFillColumns[columnEntry];
DataGridViewColumn dataGridViewColumn = autoFillColumns[columnEntry];
weightDiscrepancy = Math.Abs(dataGridViewColumn.UsedFillWeight - dataGridViewColumn.FillWeight) / dataGridViewColumn.FillWeight;
if (weightDiscrepancy > biggestWeightDiscrepancy || mostDeservingDataGridViewColumn is null)
{
Expand Down