PowerTools MultiRow for Windows Forms 8.0J
Section クラス
メンバ  使用例 

GcMultiRowコントロール内の要素の線形コレクションを表します。このクラスは抽象 (Visual BasicではMustInherit)クラスなので、インスタンス化できません。
構文
Public MustInherit Class Section 
   Inherits System.ComponentModel.Component
public abstract class Section : System.ComponentModel.Component 
解説
Sectionクラスは、セクションに含まれる、グループとして操作可能な隣接したCell要素を表します。各要素は通常、Cellまたはそのいずれかの派生クラスのインスタンスです。Sectionは、Rowクラス、ColumnHeaderSectionクラス、およびColumnFooterSectionクラスの基本クラスです。Section型にはパブリックコンストラクターがないので、セクションにアクセスするには常に、GcMultiRow内のRowColumnHeaderSection、およびColumnFooterSectionを使用する必要があります。
使用例
次のサンプルコードは、セクションの使用方法を示します。行、ヘッダ、フッタはどれもセクションです。セクションの外観は、プロパティを変更することによって変更できます。テストするには各ボタンをクリックします。
using System;
using System.Drawing;
using System.Windows.Forms;

namespace GrapeCity.Win.MultiRow.SampleCode
{
    public class SectionDemo : Form
    {
        private GcMultiRow gcMultiRow1 = new GcMultiRow();
        private FlowLayoutPanel panel = new FlowLayoutPanel();

        public SectionDemo()
        {
            this.Text = "Section Demo";
            this.Size = new Size(450, 350);

            // Initial flow layout panel and add to form.
            this.panel.Dock = DockStyle.Left;
            this.panel.Size = new Size(200, 200);
            this.panel.FlowDirection = FlowDirection.TopDown;
            this.panel.WrapContents = false;
            this.panel.Padding = new Padding(5);
            this.Controls.Add(panel);

            // Add MultiRow to form
            this.gcMultiRow1.Dock = DockStyle.Left;
            this.Controls.Add(this.gcMultiRow1);

            this.Load += new EventHandler(Form1_Load);
            
            InitButton();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gcMultiRow1.Template = Template.Default;

            gcMultiRow1.RowCount = 5;

            // Fill values.
            for (int rowIndex = 0; rowIndex < gcMultiRow1.RowCount; rowIndex++)
            {
                gcMultiRow1[rowIndex, 0].Value = rowIndex.ToString();
            }

            // Keep the values when change MultiRow control's template.
            gcMultiRow1.RestoreValue = true;
        }

        #region Button Event Handlers

        void setBackColorButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            Section section = template.Row;

            section.BackColor = Color.Yellow;

            // Reload template.
            this.gcMultiRow1.Template = template;
        }

        void setPattenButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            Section section = template.Row;

            // The PatternColor, PatternStyle should be use together
            section.PatternColor = Color.Red;
            section.PatternStyle = MultiRowHatchStyle.BackwardDiagonal;

            // Reload template.
            this.gcMultiRow1.Template = template;
        }

        void setGradientColorButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            Section section = template.Row;

            // The GradientColors, GradientDirection, GradientStyle should be use together
            section.GradientColors = new Color[] { Color.Red, Color.Blue };
            section.GradientDirection = GradientDirection.Center;
            section.GradientStyle = GradientStyle.Vertical;

            // Reload template.
            this.gcMultiRow1.Template = template;
        }

        void setBorderButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            // Change row section border.
            Section rowSection = template.Row;
            rowSection.Border = new RoundedBorder(LineStyle.Double, Color.Red, 0.3f);

            // Change column header section border.
            Section headerSection = template.ColumnHeaders[0];
            headerSection.Border = new RoundedBorder(LineStyle.Double, Color.Red, 0.3f);

            // Reload template.
            this.gcMultiRow1.Template = template;
        }

        void setHeightButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            Section section = template.Row;

            // When change section height, the cell's height do not change together.
            // Yow can add more cells, or adjust some cell's size to fit new template size.
            section.Height = 50;

            // Reload template.
            this.gcMultiRow1.Template = template;
        }

        void setVisibleButton_Click(object sender, EventArgs e)
        {
            gcMultiRow1.Rows[0].Visible = !gcMultiRow1.Rows[0].Visible;
        }

        void setSelectButton_Click(object sender, EventArgs e)
        {
            gcMultiRow1.Rows[1].Selected = !gcMultiRow1.Rows[1].Selected;
        }

        void editColumnHeaderFooterButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            ColumnHeaderSection columnHeaderSection = new ColumnHeaderSection();

            columnHeaderSection.Height = 20;

            TextBoxCell textBoxCell = new TextBoxCell();

            textBoxCell.Size = new Size(template.Width, 20);

            textBoxCell.Value = "The cell in header section, try to edit it";

            columnHeaderSection.Cells.Add(textBoxCell);

            // In default, the cell in the column header section can't be select,
            // If you set column header section's Selectable property to true, the cell can be selected.
            columnHeaderSection.Selectable = true;

            // Event if the column header can be selected, in default, the cell in the column header section can't be edited,
            // If you set column header section's ReadOnly property to false, the cell can be edited.
            columnHeaderSection.ReadOnly = false;

            template.ColumnHeaders.Add(columnHeaderSection);

            // Reload template.
            gcMultiRow1.Template = template;
        }

        void setPrintableButton_Click(object sender, EventArgs e)
        {
            Template template = Template.Default;

            Section displayHeaderSection = template.ColumnHeaders[0];

            ColumnHeaderSection printHeaderSection = new ColumnHeaderSection();

            printHeaderSection.Height = 40;

            // Initialize and add a PrintInfoCell into printHeaderSection.
            PrintInfoCell printInfoCell = new PrintInfoCell();

            printInfoCell.FormatString = "{PageNumber} of {PageCount}";

            printInfoCell.Size = new Size(template.Width, printHeaderSection.Height);

            printHeaderSection.Cells.Add(printInfoCell);

            template.ColumnHeaders.Add(printHeaderSection);

            // The section only use to display in screen.
            displayHeaderSection.Printable = false;
            displayHeaderSection.Visible = true;

            // The section only use to display when print.
            printHeaderSection.Visible = false;
            printHeaderSection.Printable = true;

            // Reload template
            this.gcMultiRow1.Template = template;
            this.gcMultiRow1.RowCount = 100;

            // Print column header in every page.
            this.gcMultiRow1.PrintSettings.PrintHeader = PrintHeader.AllPages;

            try
            {
                this.gcMultiRow1.PrintPreview();
            }
            catch(Exception ex)
            {
                // Can't find printer.
                MessageBox.Show(ex.Message);
            }
        }

        #endregion

        #region Initialize Buttons

        private void InitButton()
        {
            AddButton(setBackColorButton, "Set BackColor", new EventHandler(setBackColorButton_Click));
            AddButton(setPattenButton, "Set Patten", new EventHandler(setPattenButton_Click));
            AddButton(setGradientColorButton, "Set Gradient Color", new EventHandler(setGradientColorButton_Click));
            AddButton(setBorderButton, "Set Border", new EventHandler(setBorderButton_Click));
            AddButton(setHeightButton, "Set Height", new EventHandler(setHeightButton_Click));
            AddButton(setVisibleButton, "Set Visible to 1st row", new EventHandler(setVisibleButton_Click));
            AddButton(setSelectButton, "Set Select to 2nd row", new EventHandler(setSelectButton_Click));
            AddButton(editColumnHeaderFooterButton, "Edit header", new EventHandler(editColumnHeaderFooterButton_Click));
            AddButton(setPrintableButton, "Set Printable", new EventHandler(setPrintableButton_Click));
        }

        private void AddButton(Button button, string text, EventHandler eventHandler)
        {
            this.panel.Controls.Add(button);
            button.Text = text;
            button.AutoSize = true;
            button.Click += eventHandler;
        }

        Button setBackColorButton = new Button();
        Button setPattenButton = new Button();
        Button setGradientColorButton = new Button();
        Button setBorderButton = new Button();
        Button setHeightButton = new Button();
        Button setVisibleButton = new Button();
        Button setSelectButton = new Button();
        Button editColumnHeaderFooterButton = new Button();
        Button setPrintableButton = new Button();

        #endregion

        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new SectionDemo());
        }
    }
}
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports GrapeCity.Win.MultiRow

Public Class SectionDemo
    Inherits Form
    Private gcMultiRow1 As New GcMultiRow()
    Private panel As New FlowLayoutPanel()

    Public Sub New()
        Me.Text = "Section Demo"
        Me.Size = New Size(450, 350)

        ' Initial flow layout panel and add to form.
        Me.panel.Dock = DockStyle.Left
        Me.panel.Size = New Size(200, 200)
        Me.panel.FlowDirection = FlowDirection.TopDown
        Me.panel.WrapContents = False
        Me.panel.Padding = New Padding(5)
        Me.Controls.Add(panel)

        ' Add MultiRow to form
        Me.gcMultiRow1.Dock = DockStyle.Left
        Me.Controls.Add(Me.gcMultiRow1)
        InitButton()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        gcMultiRow1.Template = Template.Default

        gcMultiRow1.RowCount = 5

        ' Fill values.
        For rowIndex As Integer = 0 To gcMultiRow1.RowCount - 1
            gcMultiRow1(rowIndex, 0).Value = rowIndex.ToString()
        Next

        ' Keep the values when change MultiRow control's template.
        gcMultiRow1.RestoreValue = True
    End Sub

#Region "Button Event Handlers"

    Private Sub setBackColorButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setBackColorButton.Click
        Dim template1 As Template = Template.Default

        Dim section As Section = template1.Row

        section.BackColor = Color.Yellow

        ' Reload template.
        Me.gcMultiRow1.Template = template1
    End Sub

    Private Sub setPattenButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setPattenButton.Click
        Dim template1 As Template = Template.Default

        Dim section As Section = template1.Row

        ' The PatternColor, PatternStyle should be use together
        section.PatternColor = Color.Red
        section.PatternStyle = MultiRowHatchStyle.BackwardDiagonal

        ' Reload template.
        Me.gcMultiRow1.Template = template1
    End Sub

    Private Sub setGradientColorButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setGradientColorButton.Click
        Dim template1 As Template = Template.Default

        Dim section As Section = template1.Row

        ' The GradientColors, GradientDirection, GradientStyle should be use together
        section.GradientColors = New Color() {Color.Red, Color.Blue}
        section.GradientDirection = GradientDirection.Center
        section.GradientStyle = GradientStyle.Vertical

        ' Reload template.
        Me.gcMultiRow1.Template = template1
    End Sub

    Private Sub setBorderButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setBorderButton.Click
        Dim template1 As Template = Template.Default

        ' Change row section border.
        Dim rowSection As Section = template1.Row
        rowSection.Border = New RoundedBorder(LineStyle.Double, Color.Red, 0.3F)

        ' Change column header section border.
        Dim headerSection As Section = template1.ColumnHeaders(0)
        headerSection.Border = New RoundedBorder(LineStyle.Double, Color.Red, 0.3F)

        ' Reload template.
        Me.gcMultiRow1.Template = template1
    End Sub

    Private Sub setHeightButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setHeightButton.Click
        Dim template1 As Template = Template.Default

        Dim section As Section = template1.Row

        ' When change section height, the cell's height do not change together.
        ' Yow can add more cells, or adjust some cell's size to fit new template size.
        section.Height = 50

        ' Reload template.
        Me.gcMultiRow1.Template = template1
    End Sub

    Private Sub setVisibleButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setVisibleButton.Click
        gcMultiRow1.Rows(0).Visible = Not gcMultiRow1.Rows(0).Visible
    End Sub

    Private Sub setSelectButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setSelectButton.Click
        gcMultiRow1.Rows(1).Selected = Not gcMultiRow1.Rows(1).Selected
    End Sub

    Private Sub editColumnHeaderFooterButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles editColumnHeaderFooterButton.Click
        Dim template1 As Template = Template.Default

        Dim columnHeaderSection As New ColumnHeaderSection()

        columnHeaderSection.Height = 20

        Dim textBoxCell As New TextBoxCell()

        textBoxCell.Size = New Size(template1.Width, 20)

        textBoxCell.Value = "The cell in header section, try to edit it"

        columnHeaderSection.Cells.Add(textBoxCell)

        ' In default, the cell in the column header section can't be select,
        ' If you set column header section's Selectable property to true, the cell can be selected.
        columnHeaderSection.Selectable = True

        ' Event if the column header can be selected, in default, the cell in the column header section can't be edited,
        ' If you set column header section's ReadOnly property to false, the cell can be edited.
        columnHeaderSection.ReadOnly = False

        template1.ColumnHeaders.Add(columnHeaderSection)

        ' Reload template.
        gcMultiRow1.Template = template1
    End Sub

    Private Sub setPrintableButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setPrintableButton.Click
        Dim template1 As Template = Template.Default

        Dim displayHeaderSection As Section = template1.ColumnHeaders(0)

        Dim printHeaderSection As New ColumnHeaderSection()

        printHeaderSection.Height = 40

        ' Initialize and add a PrintInfoCell into printHeaderSection.
        Dim printInfoCell As New PrintInfoCell()

        printInfoCell.FormatString = "{PageNumber} of {PageCount}"

        printInfoCell.Size = New Size(template1.Width, printHeaderSection.Height)

        printHeaderSection.Cells.Add(printInfoCell)

        template1.ColumnHeaders.Add(printHeaderSection)

        ' The section only use to display in screen.
        displayHeaderSection.Printable = False
        displayHeaderSection.Visible = True

        ' The section only use to display when print.
        printHeaderSection.Visible = False
        printHeaderSection.Printable = True

        ' Reload template
        Me.gcMultiRow1.Template = template1
        Me.gcMultiRow1.RowCount = 100

        ' Print column header in every page.
        Me.gcMultiRow1.PrintSettings.PrintHeader = PrintHeader.AllPages

        Try
            Me.gcMultiRow1.PrintPreview()
        Catch ex As Exception
            ' Can't find printer.
            MessageBox.Show(ex.Message)
        End Try
    End Sub

#End Region

#Region "Initialize Buttons"

    Private Sub InitButton()
        AddButton(setBackColorButton, "Set BackColor")
        AddButton(setPattenButton, "Set Patten")
        AddButton(setGradientColorButton, "Set Gradient Color")
        AddButton(setBorderButton, "Set Border")
        AddButton(setHeightButton, "Set Height")
        AddButton(setVisibleButton, "Set Visible to 1st row")
        AddButton(setSelectButton, "Set Select to 2nd row")
        AddButton(editColumnHeaderFooterButton, "Edit header")
        AddButton(setPrintableButton, "Set Printable")
    End Sub

    Private Sub AddButton(ByVal button As Button, ByVal text As String)
        Me.panel.Controls.Add(button)
        button.Text = text
        button.AutoSize = True
    End Sub

    Friend WithEvents setBackColorButton As New Button()
    Friend WithEvents setPattenButton As New Button()
    Friend WithEvents setGradientColorButton As New Button()
    Friend WithEvents setBorderButton As New Button()
    Friend WithEvents setHeightButton As New Button()
    Friend WithEvents setVisibleButton As New Button()
    Friend WithEvents setSelectButton As New Button()
    Friend WithEvents editColumnHeaderFooterButton As New Button()
    Friend WithEvents setPrintableButton As New Button()

#End Region

    <STAThreadAttribute()> _
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New SectionDemo())
    End Sub
End Class
継承階層

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         GrapeCity.Win.MultiRow.Section
            GrapeCity.Win.MultiRow.ColumnFooterSection
            GrapeCity.Win.MultiRow.ColumnHeaderSection
            GrapeCity.Win.MultiRow.Row

参照

Section メンバ
GrapeCity.Win.MultiRow 名前空間
ColumnHeaderSection クラス
Row クラス
ColumnFooterSection クラス

 

 


© 2008-2015 GrapeCity inc. All rights reserved.