MESCIUS SPREAD for Windows Forms 17.0J サンプルコード集
コーディングによるグループ化

グループデータモデルにソート情報を設定することにより、任意のタイミング(ボタンクリックイベントなど)で行のグループ化を実現することができます。

【実行例】

グループ化

  • グループ化機能といくつかの機能(ソートや行フィルタリングなど)は併用することができません。詳細については、開発者ガイド 「Web サイトグループ化の制限事項」 を参照してください。

 private void Form1_Load(object sender, EventArgs e)
 {

   // グループ化を許可します
   fpSpread1.ActiveSheet.AllowGroup = true;

   fpSpread1.ActiveSheet.ColumnCount = 4;
   fpSpread1.ActiveSheet.RowCount = 4;
   fpSpread1.ActiveSheet.Columns[0].Label = "名前";
   fpSpread1.ActiveSheet.Columns[1].Label = "性別";
   fpSpread1.ActiveSheet.Columns[2].Label = "報酬";
   fpSpread1.ActiveSheet.Columns[3].Label = "職業";
   fpSpread1.ActiveSheet.Cells[0, 0].Value = "Jack";
   fpSpread1.ActiveSheet.Cells[0, 1].Value = "Male";
   fpSpread1.ActiveSheet.Cells[0, 2].Value = "3000 USD";
   fpSpread1.ActiveSheet.Cells[0, 3].Value = "Teacher";
   fpSpread1.ActiveSheet.Cells[1, 0].Value = "Tommy";
   fpSpread1.ActiveSheet.Cells[1, 1].Value = "Male";
   fpSpread1.ActiveSheet.Cells[1, 2].Value = "3000 USD";
   fpSpread1.ActiveSheet.Cells[1, 3].Value = "Developer";
   fpSpread1.ActiveSheet.Cells[2, 0].Value = "Cassie";
   fpSpread1.ActiveSheet.Cells[2, 1].Value = "FeMale";
   fpSpread1.ActiveSheet.Cells[2, 2].Value = "3200 USD";
   fpSpread1.ActiveSheet.Cells[2, 3].Value = "Teacher";
   fpSpread1.ActiveSheet.Cells[3, 0].Value = "Mary";
   fpSpread1.ActiveSheet.Cells[3, 1].Value = "FeMale";
   fpSpread1.ActiveSheet.Cells[3, 2].Value = "2700 USD";
   fpSpread1.ActiveSheet.Cells[3, 3].Value = "Accountant";

 }

 private void button1_Click(object sender, EventArgs e)
 {

   // 2列目でグループ化を行います
   FarPoint.Win.Spread.Model.GroupDataModel gm = new FarPoint.Win.Spread.Model.GroupDataModel(fpSpread1.ActiveSheet.Models.Data);
   FarPoint.Win.Spread.SortInfo[] sort = new FarPoint.Win.Spread.SortInfo[1];
   sort[0] = new FarPoint.Win.Spread.SortInfo(1, true);
   gm.Group(sort);
   fpSpread1.ActiveSheet.Models.Data = gm;

 }
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   ' グループ化を許可します
   FpSpread1.ActiveSheet.AllowGroup = True

   FpSpread1.ActiveSheet.ColumnCount = 4
   FpSpread1.ActiveSheet.RowCount = 4
   FpSpread1.ActiveSheet.Columns(0).Label = "名前"
   FpSpread1.ActiveSheet.Columns(1).Label = "性別"
   FpSpread1.ActiveSheet.Columns(2).Label = "報酬"
   FpSpread1.ActiveSheet.Columns(3).Label = "職業"
   FpSpread1.ActiveSheet.Cells(0, 0).Value = "Jack"
   FpSpread1.ActiveSheet.Cells(0, 1).Value = "Male"
   FpSpread1.ActiveSheet.Cells(0, 2).Value = "3000 USD"
   FpSpread1.ActiveSheet.Cells(0, 3).Value = "Teacher"
   FpSpread1.ActiveSheet.Cells(1, 0).Value = "Tommy"
   FpSpread1.ActiveSheet.Cells(1, 1).Value = "Male"
   FpSpread1.ActiveSheet.Cells(1, 2).Value = "3000 USD"
   FpSpread1.ActiveSheet.Cells(1, 3).Value = "Developer"
   FpSpread1.ActiveSheet.Cells(2, 0).Value = "Cassie"
   FpSpread1.ActiveSheet.Cells(2, 1).Value = "FeMale"
   FpSpread1.ActiveSheet.Cells(2, 2).Value = "3200 USD"
   FpSpread1.ActiveSheet.Cells(2, 3).Value = "Teacher"
   FpSpread1.ActiveSheet.Cells(3, 0).Value = "Mary"
   FpSpread1.ActiveSheet.Cells(3, 1).Value = "FeMale"
   FpSpread1.ActiveSheet.Cells(3, 2).Value = "2700 USD"
   FpSpread1.ActiveSheet.Cells(3, 3).Value = "Accountant"

 End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

   ' 2列目でグループ化を行います
   Dim gm As New FarPoint.Win.Spread.Model.GroupDataModel(FpSpread1.ActiveSheet.Models.Data)
   Dim sort(0) As FarPoint.Win.Spread.SortInfo
   sort(0) = New FarPoint.Win.Spread.SortInfo(1, True)
   gm.Group(sort)
   FpSpread1.ActiveSheet.Models.Data = gm

 End Sub

 

 


© MESCIUS inc. All rights reserved.