public class CustC1FlexGrid : C1FlexGrid
{ //用來儲存合併範圍Index的物件
private class CellRangeIndex
{ public int StartRow, StartCol, EndRow, EndCol;
public CellRangeIndex(
int startRow, int startCol,
int endRow, int endCol)
{ StartRow = startRow;
EndRow = endRow;
StartCol = startCol;
EndCol = endCol;
}
}
#region Constructor & Dispose(略)
#endregion
//儲存合併設定
CellRangeIndex[,] mergeMapping = null;
//是否需要處理合併
bool needMerging = false;
//指定哪幾個Cell合併成一個
public void MergeCells(int startRowIdx, int startColIdx,
int endRowIdx, int endColIdx)
{ needMerging = true;
CellRangeIndex cri =
new CellRangeIndex(startRowIdx, startColIdx,
endRowIdx, endColIdx);
for (int i=startRowIdx; i<=endRowIdx; i++)
for (int j=startColIdx; j<=endColIdx; j++)
mergeMapping[i, j]=cri;
}
//Header的Row數
private int HEADER_ROW_COUNT = 2;
//設定必要的合併用參數及變數
public void InitMergeSetting()
{ this.AllowMerging = AllowMergingEnum.FixedOnly;
for (int r = 0; r < HEADER_ROW_COUNT; r++)
Rows[r].AllowMerging = true;
for (int c = 0; c < Cols.Count; c++)
Cols[c].AllowMerging = true;
mergeMapping =
new CellRangeIndex[HEADER_ROW_COUNT, Cols.Count];
}
//自訂欄位合併的邏輯
public override CellRange GetMergedRange
(int row, int col, bool clip)
{ if (needMerging &&
row < HEADER_ROW_COUNT &&
mergeMapping[row, col]!=null)
{ CellRangeIndex cri = mergeMapping[row, col];
return base.GetCellRange(
cri.StartRow, cri.StartCol,
cri.EndRow, cri.EndCol);
}
return base.GetCellRange(row, col);
}
#region Component Designer generated code
#endregion
}