private void Form1_Load(object sender, System.EventArgs e)
{
//データセットを手動で作成します
DataSet ds = new DataSet();
DataTable fpParent;
DataTable fpChild1;
fpParent = ds.Tables.Add("SampleTable");
fpParent.Columns.AddRange(new DataColumn[] {
new DataColumn("Name", Type.GetType("System.String")),
new DataColumn("ID", Type.GetType("System.Int32"))});
fpParent.Rows.Add(new object[] {"親データ1", 123});
fpParent.Rows.Add(new object[] {"親データ2", 456});
fpChild1 = ds.Tables.Add("ChildTable");
fpChild1.Columns.AddRange(new DataColumn[] {
new DataColumn("Child-Name", Type.GetType("System.String")),
new DataColumn("ID", Type.GetType("System.Int32"))});
fpChild1.Rows.Add(new object[] {"子データ1-1", 123});
fpChild1.Rows.Add(new object[] {"子データ1-2", 123});
fpChild1.Rows.Add(new object[] {"子データ2-1", 456});
//テーブル間のリレーションを設定します
ds.Relations.Add("Relation1", fpParent.Columns["ID"], fpChild1.Columns["ID"]);
//作成されたデータセットを接続します
fpSpread1.ActiveSheet.DataSource = ds;
//全ての階層を展開します
fpSpread1.ActiveSheet.ExpandRow(-1, true);
fpSpread1.FocusRenderer = new FarPoint.Win.Spread.SolidFocusIndicatorRenderer(Color.Red, 2);
fpSpread1.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never;
fpSpread1.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never;
}
private void button1_Click(object sender, System.EventArgs e)
{
FarPoint.Win.Spread.SpreadView ParentView;
FarPoint.Win.Spread.SheetView ChildSheetView;
//(1)アクティブな子シートビューを取得します
ChildSheetView = fpSpread1.GetRootWorkbook().GetActiveWorkbook().GetSheetView();
//(2)親ワークブックを取得します
ParentView = fpSpread1.GetRootWorkbook().GetSpreadView(fpSpread1.Sheets[0], 0, 0);
//(3)親ワークブックをアクティブにします
fpSpread1.GetRootWorkbook().SetActiveWorkbook(ParentView);
//(4)親ワークブック上のセルをアクティブにします
ChildSheetView.ClearSelection();
fpSpread1.Sheets[0].SetActiveCell(ChildSheetView.ParentRowIndex, 0);
fpSpread1.Invalidate();
}
private void fpSpread1_ChildWorkbookCreated(object sender, FarPoint.Win.Spread.ChildWorkbookCreatedEventArgs e)
{
//子ワークブックのデザインを設定します(当手法に直接的な関係はありません)
e.Workbook.FocusRenderer = new FarPoint.Win.Spread.SolidFocusIndicatorRenderer(Color.Red, 2);
e.Workbook.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never;
e.Workbook.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never;
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'データセットを作成します
Dim ds As New DataSet
Dim fpParent As DataTable
Dim fpChild1 As DataTable
fpParent = ds.Tables.Add("SampleTable")
fpParent.Columns.AddRange(New DataColumn() { _
New DataColumn("Name", Type.GetType("System.String")), _
New DataColumn("ID", Type.GetType("System.Int32"))})
fpParent.Rows.Add(New Object() {"親データ1", 123})
fpParent.Rows.Add(New Object() {"親データ2", 456})
fpChild1 = ds.Tables.Add("ChildTable")
fpChild1.Columns.AddRange(New DataColumn() { _
New DataColumn("Child-Name", Type.GetType("System.String")), _
New DataColumn("ID", Type.GetType("System.Int32"))})
fpChild1.Rows.Add(New Object() {"子データ1-1", 123})
fpChild1.Rows.Add(New Object() {"子データ1-2", 123})
fpChild1.Rows.Add(New Object() {"子データ2-1", 456})
'テーブル間のリレーションを設定します
ds.Relations.Add("Relation1", fpParent.Columns("ID"), fpChild1.Columns("ID"))
'作成されたデータセットを接続します
FpSpread1.ActiveSheet.DataSource = ds
'全ての階層を展開します
FpSpread1.ActiveSheet.ExpandRow(-1, True)
FpSpread1.FocusRenderer = New FarPoint.Win.Spread.SolidFocusIndicatorRenderer(Color.Red, 2) FpSpread1.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never
FpSpread1.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ParentView As FarPoint.Win.Spread.SpreadView
Dim ChildSheetView As FarPoint.Win.Spread.SheetView
'(1)アクティブな子シートビューを取得します
ChildSheetView = FpSpread1.GetRootWorkbook.GetActiveWorkbook.GetSheetView
'(2)親ワークブックを取得します
ParentView = FpSpread1.GetRootWorkbook.GetSpreadView(FpSpread1.Sheets(0), 0, 0)
'(3)親ワークブックをアクティブにします
FpSpread1.GetRootWorkbook.SetActiveWorkbook(ParentView)
'(4)親ワークブック上のセルをアクティブにします
ChildSheetView.ClearSelection()
FpSpread1.Sheets(0).SetActiveCell(ChildSheetView.ParentRowIndex, 0)
FpSpread1.Invalidate()
End Sub
Private Sub FpSpread1_ChildWorkbookCreated(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChildWorkbookCreatedEventArgs) Handles FpSpread1.ChildWorkbookCreated
'子ワークブックのデザインを設定します(当手法に直接的な関係はありません)
e.Workbook.FocusRenderer = New FarPoint.Win.Spread.SolidFocusIndicatorRenderer(Color.Red, 2)
e.Workbook.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never
e.Workbook.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.Never
End Sub