用于设置列位置的类。网格名称是 filtergrid。其他事情几乎可以解释。我们只在设计中声明了网格(由于某种我们不知道的原因,我们在代码中声明网格时无法使用此函数)。所有其他设置都是在代码中完成的。
const int NoOfCols = 7;
private void SetDefaultColumnPositions(RowLayoutColumnInfosCollection colInfos)
{
int totalColWidth = 0;
int visibleColumnCount = 0;
foreach (RowLayoutColumnInfo rlColInfo in colInfos)
{
if (rlColInfo.Column.Hidden == false)
{
visibleColumnCount++;
totalColWidth += rlColInfo.Column.CellSizeResolved.Width;
}
}
int NO_OF_ROWS = Convert.ToInt32(System.Math.Ceiling(visibleColumnCount * 1.0 / NoOfCols));
int columnCount = 0;
_filterGrid.Height = 22 * (NO_OF_ROWS);
if (columnCount == colInfos.Count)
{
return;
}
for (int i = 0; i < NO_OF_ROWS; i++)
{
for (int j = 0; j < NoOfCols; j++)
{
if (columnCount >= colInfos.Count)
{
return;
}
while (colInfos[columnCount].Column.Hidden)
{
++columnCount;
if (columnCount >= colInfos.Count)
{
return;
}
}
if (columnCount < colInfos.Count)
{
colInfos[columnCount].Initialize((j +2) * 2, i * 2);
++columnCount;
}
if (columnCount >= colInfos.Count)
{
break;
}
}
if (columnCount >= colInfos.Count)
{
break;
}
}
}