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

カスタマイズされたSystem.Windows.Forms.CommonDialogまたはSystem.Windows.Forms.FormをポップアップできるCellを表します。ポップアップしたCommonDialogまたはFormで編集すると、編集した結果がPopupCellのテキストフレームに表示されます。
構文
Public Class PopupCell 
   Inherits Cell
public class PopupCell : Cell 
解説

PopupCellクラスは、特別なタイプの値を表示および編集するために使用する、特別なタイプのCellです。PopupCellEditingControlIEditingControlインタフェースを実装しているので、値を編集できます。ユーザーがダイアログまたはフォームをポップアップして、セルの値を編集することもできます。

継承時の注意:

PopupCellから継承した派生クラスに新しいプロパティを追加するときは、必ずCloneメソッドをオーバーライドして、クローニング操作時に新しいプロパティがコピーされるようにしてください。また、基本クラスのCloneメソッドを呼び出して、基本クラスのプロパティが新しいセルにコピーされるようにしてください。

使用例
次のサンプルコードは、ポップアップ型セルを使用する方法と、このセルのプロパティをカスタマイズする方法を示します。
using System;
using System.Drawing;
using System.Windows.Forms;

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

        public PopupCellDemo()
        {
            this.Text = "PopupCell Demo";
            this.Size = new Size(560, 300);

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

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

        private void Form1_Load(object sender, EventArgs e)
        {
            // create a template with PopupCells.
            PopupCell colorPopupCell = this.CreateColorPopupCell();

            PopupCell customTypePopupCell = this.CreateCustomTypePopupCell();

            PopupCell customButtonAppearancePopupCell = this.CreateCustomButtonAppearancePopupCell();
            
            PopupCell hiddenButtonPopupCell = this.CreateHiddenButtonPopupCell();

            Cell[] popupCells = new Cell[] { colorPopupCell, customTypePopupCell, customButtonAppearancePopupCell, hiddenButtonPopupCell };

            this.gcMultiRow1.Template = Template.CreateGridTemplate(popupCells);

            this.gcMultiRow1.ColumnHeaders[0][0].Value = "Color";
            this.gcMultiRow1.ColumnHeaders[0][1].Value = "Custom Type";
            this.gcMultiRow1.ColumnHeaders[0][2].Value = "Custom Button Appearance";
            this.gcMultiRow1.ColumnHeaders[0][3].Value = "Hidden button";

            FillData();

            this.gcMultiRow1.CellFormatting += new EventHandler<CellFormattingEventArgs>(gcMultiRow1_CellFormatting);
        }

        PopupCell CreateColorPopupCell()
        {
            PopupCell popupCell1 = new PopupCell();

            // Pop up ColorDialog when click button.
            popupCell1.Popup = new ColorDialog();
            // Use ColorDialog's Color property's value as cell's value.
            popupCell1.PopupValueMember = "Color";
            popupCell1.Name = "Color";
            popupCell1.Size = new Size(80, 21);

            return popupCell1;
        }

        void gcMultiRow1_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellName == "Color")
            {
                if (e.Value != null)
                {
                    e.CellStyle.BackColor = (Color)e.Value;
                }
            }
        }

        PopupCell CreateCustomTypePopupCell()
        {
            PopupCell popupCell1 = new PopupCell();

            // Pop up student edit form when click button.
            popupCell1.Popup = new StudentEditForm();
            // Use student edit form's Student property's value as cell's value.
            popupCell1.PopupValueMember = "Student";
            popupCell1.TextBoxReadOnly = true;
            popupCell1.Size = new Size(150, 21);

            return popupCell1;
        }

        class StudentEditForm : Form
        {
            TextBox idTextBox = new TextBox();
            TextBox nameTextBox = new TextBox();

            public StudentEditForm()
            {
                // Initialize student edit form.
                FlowLayoutPanel panel = new FlowLayoutPanel();
                panel.Size = new Size(150, 200);
                Label label1 = new Label();
                label1.Text = "Student ID:";
                Label label2 = new Label();
                label2.Text = "Student Name:";
                Button okButton = new Button();
                okButton.Text = "OK";
                okButton.DialogResult = DialogResult.OK;
                this.AcceptButton = okButton;

                this.Controls.Add(panel);
                panel.Controls.Add(label1);
                panel.Controls.Add(idTextBox);
                panel.Controls.Add(label2);
                panel.Controls.Add(nameTextBox);
                panel.Controls.Add(okButton);
                this.Text = "Student";
            }

            public Student Student
            {
                get 
                {
                    return new Student(idTextBox.Text, nameTextBox.Text);
                }
                set
                {
                    if (value != null)
                    {
                        idTextBox.Text = value.ID;
                        nameTextBox.Text = value.Name;
                    }
                }
            }
        }

        class Student
        {
            public Student(string id1, string name1)
            {
                ID = id1;
                Name = name1;
            }

            public string ID;
            public string Name;

            public override string ToString()
            {
                return "ID:" + ID + "    Name:" + Name;
            }
        }

        PopupCell CreateCustomButtonAppearancePopupCell()
        {
            PopupCell popupCell1 = new PopupCell();

            popupCell1.ButtonForeColor = Color.Red;
            popupCell1.ButtonBackColor = Color.Yellow;
            popupCell1.ButtonFlatStyle = FlatStyle.Flat;
            popupCell1.ButtonFlatAppearance.MouseOverBackColor = Color.Orange;
            popupCell1.Ellipsis = MultiRowEllipsisMode.EllipsisEnd;
            
            popupCell1.Size = new Size(130, 21);

            // Show Font dialog to edit font.
            popupCell1.Popup = new FontDialog();
            popupCell1.PopupValueMember = "Font";

            return popupCell1;
        }

        PopupCell CreateHiddenButtonPopupCell()
        {
            PopupCell popupCell1 = new PopupCell();

            popupCell1.ShowButton = CellButtonVisibility.NotShown;
            popupCell1.Size = new Size(130, 21);

            // Show OpenFileDialog to edit file name.
            popupCell1.Popup = new OpenFileDialog();
            popupCell1.PopupValueMember = "FileName";

            return popupCell1;
        }

        void FillData()
        {
            this.gcMultiRow1.Rows.Add(Color.Orange, new Student("0", "Wedy"));
            this.gcMultiRow1.Rows.Add(Color.Red, new Student("1", "Alice"));
            this.gcMultiRow1.Rows.Add(Color.Blue, new Student("2", "Mark"));
            this.gcMultiRow1.Rows.Add(Color.Yellow, new Student("3", "Gina"));
        }

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

Public Class PopupCellDemo
    Inherits Form
    Friend WithEvents gcMultiRow1 As New GcMultiRow()

    Public Sub New()
        Me.Text = "PopupCell Demo"
        Me.Size = New Size(560, 300)

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

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        ' create a template with PopupCells.
        Dim colorPopupCell As PopupCell = Me.CreateColorPopupCell()

        Dim customTypePopupCell As PopupCell = Me.CreateCustomTypePopupCell()

        Dim customButtonAppearancePopupCell As PopupCell = Me.CreateCustomButtonAppearancePopupCell()

        Dim hiddenButtonPopupCell As PopupCell = Me.CreateHiddenButtonPopupCell()

        Dim popupCells As Cell() = New Cell() {colorPopupCell, customTypePopupCell, customButtonAppearancePopupCell, hiddenButtonPopupCell}

        Me.gcMultiRow1.Template = Template.CreateGridTemplate(popupCells)

        Me.gcMultiRow1.ColumnHeaders(0)(0).Value = "Color"
        Me.gcMultiRow1.ColumnHeaders(0)(1).Value = "Custom Type"
        Me.gcMultiRow1.ColumnHeaders(0)(2).Value = "Custom Button Appearance"
        Me.gcMultiRow1.ColumnHeaders(0)(3).Value = "Hidden button"

        FillData()
    End Sub

    Private Function CreateColorPopupCell() As PopupCell
        Dim popupCell1 As New PopupCell()

        ' Pop up ColorDialog when click button.
        popupCell1.Popup = New ColorDialog()
        ' Use ColorDialog's Color property's value as cell's value.
        popupCell1.PopupValueMember = "Color"
        popupCell1.Name = "Color"
        popupCell1.Size = New Size(80, 21)

        Return popupCell1
    End Function

    Private Sub gcMultiRow1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs) Handles gcMultiRow1.CellFormatting
        If e.CellName = "Color" Then
            If e.Value <> Nothing Then
                e.CellStyle.BackColor = DirectCast(e.Value, Color)
            End If
        End If
    End Sub

    Private Function CreateCustomTypePopupCell() As PopupCell
        Dim popupCell1 As New PopupCell()

        ' Pop up student edit form when click button.
        popupCell1.Popup = New StudentEditForm()
        ' Use student edit form's Student property's value as cell's value.
        popupCell1.PopupValueMember = "Student"
        popupCell1.TextBoxReadOnly = True
        popupCell1.Size = New Size(150, 21)

        Return popupCell1
    End Function

    Private Class StudentEditForm
        Inherits Form
        Private idTextBox As New TextBox()
        Private nameTextBox As New TextBox()

        Public Sub New()
            ' Initialize student edit form.
            Dim panel As New FlowLayoutPanel()
            panel.Size = New Size(150, 200)
            Dim label1 As New Label()
            label1.Text = "Student ID:"
            Dim label2 As New Label()
            label2.Text = "Student Name:"
            Dim okButton As New Button()
            okButton.Text = "OK"
            okButton.DialogResult = DialogResult.OK
            Me.AcceptButton = okButton

            Me.Controls.Add(panel)
            panel.Controls.Add(label1)
            panel.Controls.Add(idTextBox)
            panel.Controls.Add(label2)
            panel.Controls.Add(nameTextBox)
            panel.Controls.Add(okButton)
            Me.Text = "Student"
        End Sub

        Public Property Student() As Student
            Get
                Return New Student(idTextBox.Text, nameTextBox.Text)
            End Get
            Set(ByVal value As Student)
                If Not value Is Nothing Then
                    idTextBox.Text = value.ID
                    nameTextBox.Text = value.Name
                End If
            End Set
        End Property
    End Class

    Private Class Student
        Public Sub New(ByVal id1 As String, ByVal name1 As String)
            ID = id1
            Name = name1
        End Sub

        Public ID As String
        Public Name As String

        Public Overloads Overrides Function ToString() As String
            Return "ID:" + ID + "    Name:" + Name
        End Function
    End Class

    Private Function CreateCustomButtonAppearancePopupCell() As PopupCell
        Dim popupCell1 As New PopupCell()

        popupCell1.ButtonForeColor = Color.Red
        popupCell1.ButtonBackColor = Color.Yellow
        popupCell1.ButtonFlatStyle = FlatStyle.Flat
        popupCell1.ButtonFlatAppearance.MouseOverBackColor = Color.Orange
        popupCell1.Ellipsis = MultiRowEllipsisMode.EllipsisEnd

        popupCell1.Size = New Size(130, 21)

        ' Show Font dialog to edit font.
        popupCell1.Popup = New FontDialog()
        popupCell1.PopupValueMember = "Font"

        Return popupCell1
    End Function

    Private Function CreateHiddenButtonPopupCell() As PopupCell
        Dim popupCell1 As New PopupCell()

        popupCell1.ShowButton = CellButtonVisibility.NotShown
        popupCell1.Size = New Size(130, 21)

        ' Show OpenFileDialog to edit file name.
        popupCell1.Popup = New OpenFileDialog()
        popupCell1.PopupValueMember = "FileName"

        Return popupCell1
    End Function

    Private Sub FillData()
        Me.gcMultiRow1.Rows.Add(Color.Orange, New Student("0", "Wedy"))
        Me.gcMultiRow1.Rows.Add(Color.Red, New Student("1", "Alice"))
        Me.gcMultiRow1.Rows.Add(Color.Blue, New Student("2", "Mark"))
        Me.gcMultiRow1.Rows.Add(Color.Yellow, New Student("3", "Gina"))
    End Sub

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

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         GrapeCity.Win.MultiRow.Cell
            GrapeCity.Win.MultiRow.PopupCell

参照

PopupCell メンバ
GrapeCity.Win.MultiRow 名前空間
Cell クラス
PopupEditingControl クラス

 

 


© 2008-2015 GrapeCity inc. All rights reserved.