CreateGridTemplate メソッドを使用する方法

文書番号 : 28305     文書種別 : 使用方法     最終更新日 : 2009/12/03
文書を印刷する
対象製品
MultiRow for Windows Forms 5.0J
詳細
次期バージョン MultiRow for Windows Forms 6.0J では、基本的なレイアウトのテンプレートを自動的に生成するための Template.CreateGridTemplate メソッドが提供されています。
5.0J で同様の処理を行うには、次のようなコードを実装します。

注意点:
  • 最小限の引数に対する実装例であり、追加の引数やエラーに対応する処理は含みません。
  • ビルドには Visual Studio 2008 と .NET Framework 3.5 が必要です。
  • Visual Studio 2005 または .NET Framework 2.0 の環境では、類似の機能として製品のサンプルに含まれる SimpleGrid メソッド(Sample.zip¥Functions¥VB¥Common¥SimpleGrid.vb)をご利用ください。

[Visual Basic]
Imports GrapeCity.Win.MultiRow

Private Function CreateGridTemplate(ByVal cells As IEnumerable(Of Cell)) As Template
  Dim template1 As New Template()
  Dim columnHeaderSection As New ColumnHeaderSection()
  Dim row As New Row()
  Const rowHeaderCount As Integer = 1

  ' コーナーヘッダセル
  Dim cornerHeaderCell As New ColumnHeaderCell()
  cornerHeaderCell.Name = "cornerHeaderCell"
  cornerHeaderCell.SelectionMode = MultiRowSelectionMode.AllRows
  cornerHeaderCell.Location = New Point(0, 0)
  cornerHeaderCell.HoverDirection = HoverDirection.None
  columnHeaderSection.Cells.Add(cornerHeaderCell)

  ' 行ヘッダセル
  Dim rowHeaderCell As New RowHeaderCell()
  rowHeaderCell.Name = template1.AutoGenerateCellName()
  rowHeaderCell.SelectionMode = MultiRowSelectionMode.Row
  rowHeaderCell.Location = New Point(0, 0)
  rowHeaderCell.HoverDirection = HoverDirection.Right
  rowHeaderCell.ValueFormat = "%1%"
  rowHeaderCell.Style.TextAlign = MultiRowContentAlignment.MiddleCenter
  row.Cells.Add(rowHeaderCell)

  ' 列ヘッダセル
  For i As Integer = rowHeaderCount To cells.Count() + rowHeaderCount
    Dim columnHeaderCell As New ColumnHeaderCell()
    columnHeaderCell.Name = template1.AutoGenerateCellName()
    columnHeaderCell.Location = New Point(i * columnHeaderCell.Width, columnHeaderCell.Top)
    columnHeaderCell.SelectionMode = MultiRowSelectionMode.ContainedCells
    columnHeaderCell.Style.TextAlign = MultiRowContentAlignment.MiddleCenter
    columnHeaderCell.ResizeMode = ResizeMode.Both
    columnHeaderSection.Cells.Add(columnHeaderCell)
  Next

  ' セル
  Dim cellsCount As Integer = 1
  For Each cell As Cell In cells
    cell.Location = New Point(cellsCount * rowHeaderCell.Width, 0)
    row.Cells.Add(cell)
    cellsCount += 1
  Next

  columnHeaderSection.Height = cornerHeaderCell.Height
  row.Height = rowHeaderCell.Height
  template1.Width = rowHeaderCell.Width * (cells.Count() + rowHeaderCount)
  template1.ColumnHeaders.Add(columnHeaderSection)
  template1.Row = row

  Return template1
End Function


[C#]
using GrapeCity.Win.MultiRow;

private Template CreateGridTemplate(IEnumerable<Cell> cells)
{
  Template template1 = new Template();
  ColumnHeaderSection columnHeaderSection = new ColumnHeaderSection();
  Row row = new Row();
  const int rowHeaderCount = 1;

  // コーナーヘッダセル
  ColumnHeaderCell cornerHeaderCell = new ColumnHeaderCell();
  cornerHeaderCell.Name = "cornerHeaderCell";
  cornerHeaderCell.SelectionMode = MultiRowSelectionMode.AllRows;
  cornerHeaderCell.Location = new Point(0, 0);
  cornerHeaderCell.HoverDirection = HoverDirection.None;
  columnHeaderSection.Cells.Add(cornerHeaderCell);

  // 行ヘッダセル
  RowHeaderCell rowHeaderCell = new RowHeaderCell();
  rowHeaderCell.Name = template1.AutoGenerateCellName();
  rowHeaderCell.SelectionMode = MultiRowSelectionMode.Row;
  rowHeaderCell.Location = new Point(0, 0);
  rowHeaderCell.HoverDirection = HoverDirection.Right;
  rowHeaderCell.ValueFormat = "%1%";
  rowHeaderCell.Style.TextAlign = MultiRowContentAlignment.MiddleCenter;
  row.Cells.Add(rowHeaderCell);

  // 列ヘッダセル
  for (int i = rowHeaderCount; i < (cells.Count() + rowHeaderCount); i++)
  {
    ColumnHeaderCell columnHeaderCell = new ColumnHeaderCell();
    columnHeaderCell.Name = template1.AutoGenerateCellName();
    columnHeaderCell.Location = new Point(i * columnHeaderCell.Width, columnHeaderCell.Top);
    columnHeaderCell.SelectionMode = MultiRowSelectionMode.ContainedCells;
    columnHeaderCell.Style.TextAlign = MultiRowContentAlignment.MiddleCenter;
    columnHeaderCell.ResizeMode = ResizeMode.Both;
    columnHeaderSection.Cells.Add(columnHeaderCell);
  }

  // セル
  int cellsCount = 1;
  foreach (Cell cell in cells)
  {
    cell.Location = new Point(cellsCount * rowHeaderCell.Width, 0);
    row.Cells.Add(cell);
    cellsCount += 1;
  }

  columnHeaderSection.Height = cornerHeaderCell.Height;
  row.Height = rowHeaderCell.Height;
  template1.Width = rowHeaderCell.Width * (cells.Count() + rowHeaderCount);
  template1.ColumnHeaders.Add(columnHeaderSection);
  template1.Row = row;

  return template1;
}


使用例は次のようになります。

[Visual Basic]
Imports GrapeCity.Win.MultiRow

Dim textBoxCell1 As New TextBoxCell()
Dim textBoxCell2 As New TextBoxCell()
Dim dateTimePickerCell1 As New DateTimePickerCell()

GcMultiRow1.Template = CreateGridTemplate(New Cell() { textBoxCell1, textBoxCell2, dateTimePickerCell1 })

[C#]
using GrapeCity.Win.MultiRow;

TextBoxCell textBoxCell1 = new TextBoxCell();
TextBoxCell textBoxCell2 = new TextBoxCell();
DateTimePickerCell dateTimePickerCell1 = new DateTimePickerCell();

gcMultiRow1.Template = CreateGridTemplate(new Cell[] { textBoxCell1, textBoxCell2, dateTimePickerCell1 });

6.0J のコードと比較したとき、'Template.' は不要である点に注意してください。

この文書は、以前は次のFAQ IDで公開されていました : 12703