GrapeCity.Win.MultiRow.v80 アセンブリ > GrapeCity.Win.MultiRow 名前空間 : ComboBoxCell クラス |
ComboBoxCellクラスは、コンボボックスコントロールを表示する特別なタイプのCellです。ユーザーはコンボボックスのドロップダウンリストから項目を選択することで、セルの値を編集できます。選択されたComboBoxCellはComboBoxEditingControlをホストし、ユーザーはその編集コントロールを使用してセルの値を編集できます。
継承時の注意:
ComboBoxCellから継承した派生クラスに新しいプロパティを追加するときは、必ずCloneメソッドをオーバーライドして、クローニング操作時に新しいプロパティがコピーされるようにしてください。また、基本クラスのCloneメソッドを呼び出して、基本クラスのプロパティが新しいセルにコピーされるようにしてください。
using System; using System.Drawing; using System.Windows.Forms; using System.Data; namespace GrapeCity.Win.MultiRow.SampleCode { public class ComboBoxCellDemo : Form { private GcMultiRow gcMultiRow1 = new GcMultiRow(); private Label descriptionLable = new Label(); public ComboBoxCellDemo() { this.Text = "ComboBoxCell Demo"; this.Size = new Size(400, 300); // Add MultiRow to form this.gcMultiRow1.Dock = DockStyle.Fill; this.Controls.Add(this.gcMultiRow1); descriptionLable.Height = 40; descriptionLable.BackColor = SystemColors.Info; descriptionLable.Dock = DockStyle.Bottom; this.Controls.Add(descriptionLable); this.gcMultiRow1.CellEnter += new EventHandler<CellEventArgs>(gcMultiRow1_CellEnter); this.Load += new EventHandler(Form1_Load); } private void Form1_Load(object sender, EventArgs e) { // create a template with 4 combo box cell columns. ComboBoxCell unboundComboCell = this.CreateCommonComboBoxCell(); ComboBoxCell dataBindingComboCell = this.CreateDatabindingComboBoxCell(); ComboBoxCell autoCompleteComboCell = this.CreateAutoCompleteComboBoxCell(); ComboBoxCell hiddenDropDownButtonComboCell = this.CreateComboBoxCellHiddenDropDownButton(); Cell[] comboBoxCells = new Cell[] { unboundComboCell, dataBindingComboCell, autoCompleteComboCell, hiddenDropDownButtonComboCell }; this.gcMultiRow1.Template = Template.CreateGridTemplate(comboBoxCells); this.gcMultiRow1.ColumnHeaders[0][0].Value = "Common"; this.gcMultiRow1.ColumnHeaders[0][1].Value = "Databinding"; this.gcMultiRow1.ColumnHeaders[0][2].Value = "AutoComplete"; this.gcMultiRow1.ColumnHeaders[0][3].Value = "Hide Button"; this.gcMultiRow1.RowCount = 6; } ComboBoxCell CreateCommonComboBoxCell() { ComboBoxCell comboBoxCell = new ComboBoxCell(); // The item which listed in drop down window. comboBoxCell.Items.AddRange("Item2", "Item1", "Item3", "Item4", "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 = MultiRowEllipsisMode.EllipsisEnd; return comboBoxCell; } ComboBoxCell CreateDatabindingComboBoxCell() { DataTable dataTable = this.CreatDataTable(); ComboBoxCell comboBoxCell = new ComboBoxCell(); // 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; } ComboBoxCell CreateAutoCompleteComboBoxCell() { ComboBoxCell comboBoxCell = new ComboBoxCell(); comboBoxCell.DropDownStyle = MultiRowComboBoxStyle.DropDown; comboBoxCell.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBoxCell.AutoCompleteSource = AutoCompleteSource.CustomSource; string[] customSourceItems = new string[] { "aaa", "bbb", "ccc", "ddd" }; comboBoxCell.AutoCompleteCustomSource.AddRange(customSourceItems); comboBoxCell.Items.AddRange("(none)", "aaa", "bbb", "ccc", "ddd"); return comboBoxCell; } ComboBoxCell CreateComboBoxCellHiddenDropDownButton() { ComboBoxCell comboBoxCell = new ComboBoxCell(); comboBoxCell.DropDownStyle = MultiRowComboBoxStyle.DropDown; // Hide drop down button when non edit status. comboBoxCell.ShowDropDownButton = CellButtonVisibility.NotShown; comboBoxCell.Items.AddRange("Item1", "Item2"); return comboBoxCell; } void gcMultiRow1_CellEnter(object sender, CellEventArgs e) { switch (e.CellIndex) { case 0: 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 1: 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 2: descriptionLable.Text = "When you input some char, the cell will show some recommended values. Try input 'a' or 'b' and watch what happened"; break; default: descriptionLable.Text = "Combo box cell hide its drop down button"; break; } } [STAThreadAttribute()] public static void Main() { Application.EnableVisualStyles(); Application.Run(new ComboBoxCellDemo()); } } }
Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Data Imports GrapeCity.Win.MultiRow Public Class ComboBoxCellDemo Inherits Form Friend WithEvents gcMultiRow1 As New GcMultiRow() Private descriptionLable As New Label() Public Sub New() Me.Text = "ComboBoxCell Demo" Me.Size = New Size(400, 300) ' Add MultiRow to form Me.gcMultiRow1.Dock = DockStyle.Fill Me.Controls.Add(Me.gcMultiRow1) descriptionLable.Height = 40 descriptionLable.BackColor = SystemColors.Info descriptionLable.Dock = DockStyle.Bottom Me.Controls.Add(descriptionLable) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load ' create a template with 4 combo box cell columns. Dim unboundComboCell As ComboBoxCell = Me.CreateCommonComboBoxCell() Dim dataBindingComboCell As ComboBoxCell = Me.CreateDatabindingComboBoxCell() Dim autoCompleteComboCell As ComboBoxCell = Me.CreateAutoCompleteComboBoxCell() Dim hiddenDropDownButtonComboCell As ComboBoxCell = Me.CreateComboBoxCellHiddenDropDownButton() Dim comboBoxCells As Cell() = New Cell() {unboundComboCell, dataBindingComboCell, autoCompleteComboCell, hiddenDropDownButtonComboCell} Me.gcMultiRow1.Template = Template.CreateGridTemplate(comboBoxCells) Me.gcMultiRow1.ColumnHeaders(0)(0).Value = "Common" Me.gcMultiRow1.ColumnHeaders(0)(1).Value = "Databinding" Me.gcMultiRow1.ColumnHeaders(0)(2).Value = "AutoComplete" Me.gcMultiRow1.ColumnHeaders(0)(3).Value = "Hide Button" Me.gcMultiRow1.RowCount = 6 End Sub Private Function CreateCommonComboBoxCell() As ComboBoxCell Dim comboBoxCell As New ComboBoxCell() ' The item which listed in drop down window. comboBoxCell.Items.AddRange("Item2", "Item1", "Item3", "Item4", "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 = MultiRowEllipsisMode.EllipsisEnd Return comboBoxCell End Function Private Function CreateDatabindingComboBoxCell() As ComboBoxCell Dim dataTable As DataTable = Me.CreatDataTable() Dim comboBoxCell As New ComboBoxCell() ' 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 ComboBoxCell Dim comboBoxCell As New ComboBoxCell() comboBoxCell.DropDownStyle = MultiRowComboBoxStyle.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.AddRange("(none)", "aaa", "bbb", "ccc", "ddd") Return comboBoxCell End Function Private Function CreateComboBoxCellHiddenDropDownButton() As ComboBoxCell Dim comboBoxCell As New ComboBoxCell() comboBoxCell.DropDownStyle = MultiRowComboBoxStyle.DropDown ' Hide drop down button when non edit status. comboBoxCell.ShowDropDownButton = CellButtonVisibility.NotShown comboBoxCell.Items.AddRange("Item1", "Item2") Return comboBoxCell End Function Private Sub gcMultiRow1_CellEnter(ByVal sender As Object, ByVal e As CellEventArgs) Handles gcMultiRow1.CellEnter Select Case e.CellIndex Case 0 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 1 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 2 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 Else descriptionLable.Text = _ "Combo box cell hide its drop down button" Exit Select End Select End Sub <STAThreadAttribute()> _ Public Shared Sub Main() Application.EnableVisualStyles() Application.Run(New ComboBoxCellDemo()) End Sub End Class
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
GrapeCity.Win.MultiRow.Cell
GrapeCity.Win.MultiRow.ListCell
GrapeCity.Win.MultiRow.ComboBoxCell