SourceGridで複数行を実現する。(RowSpan,ColumnSpanを使う)

以前SourceGridの話を少し書いたが、今回の.NET POSプロジェクトで実際に使うことにした。

WindowsFormにSourceGrid.Gridを貼り付け、サイズ等を設定した後、

grid1.Rows.Insert(0); grid1.Rows.Insert(1);
SourceGrid.Cells.Views.Cell header0 = new SourceGrid.Cells.Views.Cell();
header0.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.RoyalBlue, Color.LightBlue, 0);
header0.Font = grid1.Font;
header0.TextAlignment= DevAge.Drawing.ContentAlignment.MiddleCenter;
header0.ForeColor = Color.White;
grid1[0, 0] = new SourceGrid.Cells.ColumnHeader("行");grid1[0, 0].RowSpan = 2;
grid1[0, 1] = new SourceGrid.Cells.ColumnHeader("商品CD");
grid1[0, 2] = new SourceGrid.Cells.ColumnHeader("色");
grid1[0, 3] = new SourceGrid.Cells.ColumnHeader("サイズ");
grid1[1, 1] = new SourceGrid.Cells.ColumnHeader("商品名"); grid1[1, 1].ColumnSpan = 3;
grid1[0, 4] = new SourceGrid.Cells.ColumnHeader("数量"); grid1[0, 4].RowSpan = 2;
grid1[0, 5] = new SourceGrid.Cells.ColumnHeader("単価");grid1[0, 5].RowSpan = 2;
grid1[0, 6] = new SourceGrid.Cells.ColumnHeader("金額");grid1[0, 6].RowSpan = 2;
for (int i = 0; i < 7; i++) {
if (i == 1) {
grid1[1, i].View = header0;
*1.ToString()); grid1[r, 0].RowSpan = 2; grid1[r, 0].View = cell_right;
grid1[r, 1] = new SourceGrid.Cells.Cell("11-111-11");
grid1[r, 2] = new SourceGrid.Cells.Cell("BR");
grid1[r, 3] = new SourceGrid.Cells.Cell("S");
grid1[r + 1, 1] = new SourceGrid.Cells.Cell("商品名111"); grid1[r+1, 1].ColumnSpan = 3;
grid1[r, 4] = new SourceGrid.Cells.Cell(1, Type.GetType("System.Int32")); grid1[r, 4].RowSpan = 2; grid1[r, 4].View = cell_right;
grid1[r, 5] = new SourceGrid.Cells.Cell(7000, Type.GetType("System.Int32")); grid1[r, 5].RowSpan = 2; grid1[r, 5].View = cell_right;
grid1[r, 6] = new SourceGrid.Cells.Cell(7000, Type.GetType("System.Int32")); grid1[r, 6].RowSpan = 2; grid1[r, 6].View = cell_right;
}

こんな感じでコーディングする。RowSpan、CellSpanはSouceGrid.GridVirtualでもサポートしているとドキュメントには書いてあったが、SouceGrid.GridVirtualから派生したSouceGrid.DataGridでは見あたらなかったため、Gridを使った方が多分よい。(SouceGrid.GridVirtualから派生させて自作すれば可能?)
SourceGridを使ったコードってネットで調べたけどなかなか見つからなかったので、ここに掲載。。。

MEMO(106390)

*1:SourceGrid.Cells.ColumnHeader)grid1[1, i]).AutomaticSortEnabled = false; } grid1[0, i].View = header0; ((SourceGrid.Cells.ColumnHeader)grid1[0, i]).AutomaticSortEnabled = false; } grid1.Columns[0].Width = 60; grid1.Columns[1].Width = 240; grid1.Columns[2].Width = 80; grid1.Columns[3].Width = 80; grid1.Columns[4].Width = 90; grid1.Columns[5].Width = 100; grid1.Columns[6].Width = 200; SourceGrid.Cells.Views.Cell cell_right = new SourceGrid.Cells.Views.Cell(); cell_right.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight; for (int r = 2; r < 12; r += 2) { grid1.Rows.Insert(r); grid1.Rows.Insert(r); grid1[r, 0] = new SourceGrid.Cells.Cell(((int)(r / 2