GrapeCity CalendarGrid for Windows Forms 2.0J
CalendarComboBoxCellType クラス
メンバ  使用例 

GcCalendarGrid コントロール内にコンボボックスのユーザーインタフェースを表示する CalendarCellType を表します。
構文
Public Class CalendarComboBoxCellType 
   Inherits CalendarListCellType
public class CalendarComboBoxCellType : CalendarListCellType 
解説

CalendarComboBoxCellType クラスは、コンボボックスコントロールを表示する特別なタイプの CalendarCellType です。ユーザーはコンボボックスのドロップダウンリストから項目を選択することで、セルの値を編集できます。

継承時の注意:

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

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

namespace CalendarGridSampleCode
{
    public class ComboBoxCellDemo : Form
    {
        private GcCalendarGrid gcCalendarGrid1 = new GcCalendarGrid();
        
        private Label descriptionLable = new Label();

        public ComboBoxCellDemo()
        {
            this.Text = "ComboBoxCell Demo";
            this.Size = new Size(400, 300);

            // Add GcCalendarGrid to form
            this.gcCalendarGrid1.Dock = DockStyle.Fill;
            this.Controls.Add(this.gcCalendarGrid1);

            descriptionLable.Height = 40;
            descriptionLable.BackColor = SystemColors.Info;
            descriptionLable.Dock = DockStyle.Bottom;
            this.Controls.Add(descriptionLable);

            this.gcCalendarGrid1.CellEnter += gcCalendarGrid1_CellEnter;
            this.Load += Form1_Load;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // create a template with 4 combo box cells.
            CalendarComboBoxCellType unboundComboCell = this.CreateCommonComboBoxCell();

            CalendarComboBoxCellType dataBindingComboCell = this.CreateDatabindingComboBoxCell();

            CalendarComboBoxCellType autoCompleteComboCell = this.CreateAutoCompleteComboBoxCell();

            CalendarComboBoxCellType hiddenDropDownButtonComboCell = this.CreateComboBoxCellHiddenDropDownButton();

            this.gcCalendarGrid1.Template = CalendarTemplate.CreateDefaultTemplate();
            CalendarListView listView = new CalendarListView();
            listView.DayCount = 7;
            listView.Orientation = Orientation.Vertical;
            this.gcCalendarGrid1.CalendarView = listView;
            this.gcCalendarGrid1.Template.ColumnCount = 5;
            this.gcCalendarGrid1.Template.Content[0, 1].Value = "Common";
            this.gcCalendarGrid1.Template.Content[0, 2].Value = "Databinding";
            this.gcCalendarGrid1.Template.Content[0, 3].Value = "AutoComplete";
            this.gcCalendarGrid1.Template.Content[0, 4].Value = "Hide Button";

            this.gcCalendarGrid1.Template.Content[1, 1].CellType = unboundComboCell;
            this.gcCalendarGrid1.Template.Content[1, 2].CellType = dataBindingComboCell;
            this.gcCalendarGrid1.Template.Content[1, 3].CellType = autoCompleteComboCell;
            this.gcCalendarGrid1.Template.Content[1, 4].CellType = hiddenDropDownButtonComboCell;
        }

        void gcCalendarGrid1_CellEnter(object sender, CalendarCellMoveEventArgs e)
        {
            switch (e.CellPosition.ColumnIndex)
            {
                case 1:
                    descriptionLable.Text = "Common combo box cell setting. You can click the cell to show drop down list, and select a item in the list to edit cell";
                    break;
                case 2:
                    descriptionLable.Text = "The combo box cell binding to a data table which have two columns 'ID' and 'Name', drop list will lists 'Name', and when you select a item, 'ID' will be stored.";
                    break;
                case 3:
                    descriptionLable.Text = "When you input some char, the cell will show some recommended values. Try input 'a' or 'b' and watch what happened";
                    break;
                case 4:
                    descriptionLable.Text = "Combo box cell hides its drop down button";
                    break;
                default:
                    descriptionLable.Text = string.Empty;
                    break;
            }
        }

        CalendarComboBoxCellType CreateCommonComboBoxCell()
        {
            CalendarComboBoxCellType comboBoxCell = new CalendarComboBoxCellType();

            // The item which listed in drop down window. 
            comboBoxCell.Items.Add("Item2");
            comboBoxCell.Items.Add("Item1");
            comboBoxCell.Items.Add("Item3");
            comboBoxCell.Items.Add("Item4");
            comboBoxCell.Items.Add("Long Item to Make Ellipsis Show");

            // Sort items.
            comboBoxCell.Sorted = true;

            // Drop down window's width, in default, the value is equals to cell's width.
            comboBoxCell.DropDownWidth = 100;

            // In non edit status, if text's length bigger than cell's width, EllipsisString will be shown.
            comboBoxCell.Ellipsis = CalendarGridEllipsisMode.EllipsisEnd;

            return comboBoxCell;
        }

        CalendarComboBoxCellType CreateDatabindingComboBoxCell()
        {
            DataTable dataTable = this.CreatDataTable();

            CalendarComboBoxCellType comboBoxCell = new CalendarComboBoxCellType();

            // Binding items to a data source.
            comboBoxCell.DataSource = dataTable;

            // The column "Name" of data source will be use to display in the drop down list.
            comboBoxCell.DisplayMember = "Name";

            // When user select a value, the corresponding "ID" will be save as cell's value.
            comboBoxCell.ValueMember = "ID";

            return comboBoxCell;
        }

        private DataTable CreatDataTable()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("ID", typeof(int));
            dataTable.Columns.Add("Name", typeof(string));

            dataTable.Rows.Add(0, "Barry");
            dataTable.Rows.Add(1, "Colin");
            dataTable.Rows.Add(2, "Robert");
            dataTable.Rows.Add(3, "Walter");
            dataTable.Rows.Add(4, "Wedy");

            return dataTable;
        }

        CalendarComboBoxCellType CreateAutoCompleteComboBoxCell()
        {
            CalendarComboBoxCellType comboBoxCell = new CalendarComboBoxCellType();

            comboBoxCell.DropDownStyle = CalendarGridComboBoxStyle.DropDown;
            comboBoxCell.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            comboBoxCell.AutoCompleteSource = AutoCompleteSource.CustomSource;
            string[] customSourceItems = new string[] { "aaa", "bbb", "ccc", "ddd" };
            comboBoxCell.AutoCompleteCustomSource.AddRange(customSourceItems);

            comboBoxCell.Items.Add("(none)");
            comboBoxCell.Items.Add("aaa");
            comboBoxCell.Items.Add("bbb");
            comboBoxCell.Items.Add("ccc");
            comboBoxCell.Items.Add("ddd");

            return comboBoxCell;
        }

        CalendarComboBoxCellType CreateComboBoxCellHiddenDropDownButton()
        {
            CalendarComboBoxCellType comboBoxCell = new CalendarComboBoxCellType();

            comboBoxCell.DropDownStyle = CalendarGridComboBoxStyle.DropDown;

            // Hide drop down button when non edit status.
            comboBoxCell.ShowDropDownButton = CalendarCellButtonVisibility.NotShown;

            comboBoxCell.Items.Add("Item1");
            comboBoxCell.Items.Add("Item2");

            return comboBoxCell;
        }
               
        [STAThreadAttribute()]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new ComboBoxCellDemo());
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Data
Imports GrapeCity.Win.CalendarGrid

Namespace CalendarGridSampleCode
    Public Class ComboBoxCellDemo
        Inherits Form
        Private gcCalendarGrid1 As New GcCalendarGrid()

        Private descriptionLable As New Label()

        Public Sub New()
            Me.Text = "ComboBoxCell Demo"
            Me.Size = New Size(400, 300)

            ' Add GcCalendarGrid to form
            Me.gcCalendarGrid1.Dock = DockStyle.Fill
            Me.Controls.Add(Me.gcCalendarGrid1)

            descriptionLable.Height = 40
            descriptionLable.BackColor = SystemColors.Info
            descriptionLable.Dock = DockStyle.Bottom
            Me.Controls.Add(descriptionLable)

            AddHandler Me.gcCalendarGrid1.CellEnter, AddressOf gcCalendarGrid1_CellEnter
            AddHandler Me.Load, AddressOf Form1_Load
        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs)
            ' create a template with 4 combo box cells.
            Dim unboundComboCell As CalendarComboBoxCellType = Me.CreateCommonComboBoxCell()

            Dim dataBindingComboCell As CalendarComboBoxCellType = Me.CreateDatabindingComboBoxCell()

            Dim autoCompleteComboCell As CalendarComboBoxCellType = Me.CreateAutoCompleteComboBoxCell()

            Dim hiddenDropDownButtonComboCell As CalendarComboBoxCellType = Me.CreateComboBoxCellHiddenDropDownButton()

            Me.gcCalendarGrid1.Template = CalendarTemplate.CreateDefaultTemplate()
            Dim listView As New CalendarListView()
            listView.DayCount = 7
            listView.Orientation = Orientation.Vertical
            Me.gcCalendarGrid1.CalendarView = listView
            Me.gcCalendarGrid1.Template.ColumnCount = 5
            Me.gcCalendarGrid1.Template.Content(0, 1).Value = "Common"
            Me.gcCalendarGrid1.Template.Content(0, 2).Value = "Databinding"
            Me.gcCalendarGrid1.Template.Content(0, 3).Value = "AutoComplete"
            Me.gcCalendarGrid1.Template.Content(0, 4).Value = "Hide Button"

            Me.gcCalendarGrid1.Template.Content(1, 1).CellType = unboundComboCell
            Me.gcCalendarGrid1.Template.Content(1, 2).CellType = dataBindingComboCell
            Me.gcCalendarGrid1.Template.Content(1, 3).CellType = autoCompleteComboCell
            Me.gcCalendarGrid1.Template.Content(1, 4).CellType = hiddenDropDownButtonComboCell
        End Sub

        Private Sub gcCalendarGrid1_CellEnter(sender As Object, e As CalendarCellMoveEventArgs)
            Select Case e.CellPosition.ColumnIndex
                Case 1
                    descriptionLable.Text = "Common combo box cell setting. You can click the cell to show drop down list, and select a item in the list to edit cell"
                    Exit Select
                Case 2
                    descriptionLable.Text = "The combo box cell binding to a data table which have two columns 'ID' and 'Name', drop list will lists 'Name', and when you select a item, 'ID' will be stored."
                    Exit Select
                Case 3
                    descriptionLable.Text = "When you input some char, the cell will show some recommended values. Try input 'a' or 'b' and watch what happened"
                    Exit Select
                Case 4
                    descriptionLable.Text = "Combo box cell hides its drop down button"
                    Exit Select
                Case Else
                    descriptionLable.Text = String.Empty
                    Exit Select
            End Select
        End Sub

        Private Function CreateCommonComboBoxCell() As CalendarComboBoxCellType
            Dim comboBoxCell As New CalendarComboBoxCellType()

            ' The item which listed in drop down window. 
            comboBoxCell.Items.Add("Item2")
            comboBoxCell.Items.Add("Item1")
            comboBoxCell.Items.Add("Item3")
            comboBoxCell.Items.Add("Item4")
            comboBoxCell.Items.Add("Long Item to Make Ellipsis Show")

            ' Sort items.
            comboBoxCell.Sorted = True

            ' Drop down window's width, in default, the value is equals to cell's width.
            comboBoxCell.DropDownWidth = 100

            ' In non edit status, if text's length bigger than cell's width, EllipsisString will be shown.
            comboBoxCell.Ellipsis = CalendarGridEllipsisMode.EllipsisEnd

            Return comboBoxCell
        End Function

        Private Function CreateDatabindingComboBoxCell() As CalendarComboBoxCellType
            Dim dataTable As DataTable = Me.CreatDataTable()

            Dim comboBoxCell As New CalendarComboBoxCellType()

            ' Binding items to a data source.
            comboBoxCell.DataSource = dataTable

            ' The column "Name" of data source will be use to display in the drop down list.
            comboBoxCell.DisplayMember = "Name"

            ' When user select a value, the corresponding "ID" will be save as cell's value.
            comboBoxCell.ValueMember = "ID"

            Return comboBoxCell
        End Function

        Private Function CreatDataTable() As DataTable
            Dim dataTable As New DataTable()
            dataTable.Columns.Add("ID", GetType(Integer))
            dataTable.Columns.Add("Name", GetType(String))

            dataTable.Rows.Add(0, "Barry")
            dataTable.Rows.Add(1, "Colin")
            dataTable.Rows.Add(2, "Robert")
            dataTable.Rows.Add(3, "Walter")
            dataTable.Rows.Add(4, "Wedy")

            Return dataTable
        End Function

        Private Function CreateAutoCompleteComboBoxCell() As CalendarComboBoxCellType
            Dim comboBoxCell As New CalendarComboBoxCellType()

            comboBoxCell.DropDownStyle = CalendarGridComboBoxStyle.DropDown
            comboBoxCell.AutoCompleteMode = AutoCompleteMode.SuggestAppend
            comboBoxCell.AutoCompleteSource = AutoCompleteSource.CustomSource
            Dim customSourceItems As String() = New String() {"aaa", "bbb", "ccc", "ddd"}
            comboBoxCell.AutoCompleteCustomSource.AddRange(customSourceItems)

            comboBoxCell.Items.Add("(none)")
            comboBoxCell.Items.Add("aaa")
            comboBoxCell.Items.Add("bbb")
            comboBoxCell.Items.Add("ccc")
            comboBoxCell.Items.Add("ddd")

            Return comboBoxCell
        End Function

        Private Function CreateComboBoxCellHiddenDropDownButton() As CalendarComboBoxCellType
            Dim comboBoxCell As New CalendarComboBoxCellType()

            comboBoxCell.DropDownStyle = CalendarGridComboBoxStyle.DropDown

            ' Hide drop down button when non edit status.
            comboBoxCell.ShowDropDownButton = CalendarCellButtonVisibility.NotShown

            comboBoxCell.Items.Add("Item1")
            comboBoxCell.Items.Add("Item2")

            Return comboBoxCell
        End Function

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

System.Object
   GrapeCity.Win.CalendarGrid.CalendarCellType
      GrapeCity.Win.CalendarGrid.CalendarListCellType
         GrapeCity.Win.CalendarGrid.CalendarComboBoxCellType

参照

CalendarComboBoxCellType メンバ
GrapeCity.Win.CalendarGrid 名前空間

 

 


c 2008 GrapeCity inc. All rights reserved.