GcComboBoxCellに項目を追加するには、Itemsプロパティに項目のコレクションを追加する方法とデータソースを使う2通りの方法があります。
Itemsプロパティを使って、コレクションに項目を設定する場合は、GcComboBoxCellの項目(ListItem)のオブジェクトを生成し、Itemsプロパティが参照するListItemCollectionコレクションに追加します。 また、個々の項目を表すListItemは、マルチカラムを表現するためのサブアイテム(SubItem)を持っています。

一方、リストに表示する項目をデータセットなどから行う場合、データソースを使用して設定することができます。データソースを使用した場合は、Visual Studio標準のDataGridViewのようにデータソースを設定するだけで、自動的にデータと接続することができます。
それぞれの方法による項目の追加方法については、下記に解説しています。
GcComboBoxCell で、項目を選択するには、GcComboBoxEditingControl.SelectedIndex プロパティにインデックスを設定します。
次のコードは、ドロップダウンウィンドウが表示される直前に発生する DropDownOpening イベントで、SelectedIndex プロパティを使用して2番目の項目を選択するサンプルコードです。
Imports GrapeCity.Win.MultiRow
Imports InputManCell = GrapeCity.Win.MultiRow.InputMan
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim GcComboBoxCell1 As New InputManCell.GcComboBoxCell()
GcComboBoxCell1.Name = "GcComboBoxCell1"
' GcComboBoxCell にカラムを追加
GcComboBoxCell1.ListColumns.AddRange(New InputManCell.ListColumn() {New InputManCell.ListColumn("コード"), New InputManCell.ListColumn("名称")})
' GcComboBoxCell に項目を追加
GcComboBoxCell1.Items.AddRange(New InputManCell.ListItem() { _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("0001"), New InputManCell.SubItem("営業部")}), _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("0002"), New InputManCell.SubItem("開発部")}), _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("0003"), New InputManCell.SubItem("総務部")}), _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("0004"), New InputManCell.SubItem("経理部")}) _
})
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcComboBoxCell1})
End Sub
Private Sub GcMultiRow1_EditingControlShowing(sender As Object, e As GrapeCity.Win.MultiRow.EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing
If (TypeOf (e.Control) Is InputManCell.GcComboBoxEditingControl) Then
Dim editor As InputManCell.GcComboBoxEditingControl = DirectCast(e.Control, InputManCell.GcComboBoxEditingControl)
RemoveHandler editor.DropDownOpening, AddressOf editor_DropDownOpening
AddHandler editor.DropDownOpening, AddressOf editor_DropDownOpening
End If
End Sub
Private Sub editor_DropDownOpening(sender As System.Object, e As GrapeCity.Win.Editors.DropDownOpeningEventArgs)
Dim editor As InputManCell.GcComboBoxEditingControl = DirectCast(sender, InputManCell.GcComboBoxEditingControl)
editor.SelectedIndex = 1
End Sub
using GrapeCity.Win.MultiRow;
using InputManCell = GrapeCity.Win.MultiRow.InputMan;
private void Form1_Load(object sender, EventArgs e)
{
Template template = new Template();
InputManCell.GcComboBoxCell gcComboBoxCell1 = new InputManCell.GcComboBoxCell();
gcComboBoxCell1.Name = "gcComboBoxCell1";
// GcComboBoxCell にカラムを追加
gcComboBoxCell1.ListColumns.AddRange(new InputManCell.ListColumn[] { new InputManCell.ListColumn("コード"), new InputManCell.ListColumn("名称") });
// GcComboBoxCell に項目を追加
gcComboBoxCell1.Items.AddRange(new InputManCell.ListItem[] {
new InputManCell.ListItem(new InputManCell.SubItem[] {new InputManCell.SubItem("0001"), new InputManCell.SubItem("営業部")}),
new InputManCell.ListItem(new InputManCell.SubItem[] {new InputManCell.SubItem("0002"), new InputManCell.SubItem("開発部")}),
new InputManCell.ListItem(new InputManCell.SubItem[] {new InputManCell.SubItem("0003"), new InputManCell.SubItem("総務部")}),
new InputManCell.ListItem(new InputManCell.SubItem[] {new InputManCell.SubItem("0004"), new InputManCell.SubItem("経理部")})
});
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcComboBoxCell1 });
}
private void gcMultiRow1_EditingControlShowing(object sender, EditingControlShowingEventArgs e)
{
if (e.Control is InputManCell.GcComboBoxEditingControl)
{
InputManCell.GcComboBoxEditingControl editor = (InputManCell.GcComboBoxEditingControl)e.Control;
editor.DropDownOpening -= new EventHandler<GrapeCity.Win.Editors.DropDownOpeningEventArgs>(editor_DropDownOpening);
editor.DropDownOpening += new EventHandler<GrapeCity.Win.Editors.DropDownOpeningEventArgs>(editor_DropDownOpening);
}
}
private void editor_DropDownOpening(object sender, GrapeCity.Win.Editors.DropDownOpeningEventArgs e)
{
InputManCell.GcComboBoxEditingControl editor = (InputManCell.GcComboBoxEditingControl)sender;
editor.SelectedIndex = 1;
}
また、
FindStringExact メソッドを利用してインデックスを取得できます。
Console.WriteLine(DirectCast(GcMultiRow1.CurrentCell, InputManCell.GcComboBoxCell).FindStringExact("開発部", -1, 1))
Console.WriteLine((gcMultiRow1.CurrentCell as InputManCell.GcComboBoxCell).FindStringExact("開発部", -1, 1));
InputMan と共通です。
GcComboBoxCell では、項目を検索するために、上記のFindStringExact メソッドと合わせて3種類のメソッドを用意しています。これらのメソッドは、該当する最初の項目だけでなく、該当するすべての項目を保持するコレクションを戻すことができます。また、FindObject メソッドはオブジェクト型に対応しているので、DateTime型などを設定したValueMemberも検索の対象とすることができます。
次のサンプルコードは、FindObject メソッドを使ってDateTime型のサブアイテムから項目を検索する例です。
Imports GrapeCity.Win.MultiRow
Imports InputManCell = GrapeCity.Win.MultiRow.InputMan
Dim GcComboBoxCell1 As New InputManCell.GcComboBoxCell()
GcComboBoxCell1.Name = "GcComboBoxCell1"
' GcComboBoxCell にカラムを追加
GcComboBoxCell1.ListColumns.AddRange(New InputManCell.ListColumn() {
New InputManCell.ListColumn("カラム1"), New InputManCell.ListColumn("カラム2"), New InputManCell.ListColumn("カラム3")})
GcComboBoxCell1.ListColumns(0).DataDisplayType = GrapeCity.Win.Editors.DataDisplayType.Image
Dim type0 As Image = Image.FromFile("C:\Check0.bmp")
Dim type1 As Image = Image.FromFile("C:\Check1.bmp")
' GcComboBoxCell に項目を追加
GcComboBoxCell1.Items.AddRange(New InputManCell.ListItem() { _
New InputManCell.ListItem(New InputManCell.SubItem() {
New InputManCell.SubItem(type0), New InputManCell.SubItem("AAA"), New InputManCell.SubItem(DateTime.Parse("2015/2/28"))}), _
New InputManCell.ListItem(New InputManCell.SubItem() {
New InputManCell.SubItem(type1), New InputManCell.SubItem("BBB"), New InputManCell.SubItem(DateTime.Parse("2015/3/28"))}), _
New InputManCell.ListItem(New InputManCell.SubItem() {
New InputManCell.SubItem(type0), New InputManCell.SubItem("CCC"), New InputManCell.SubItem(DateTime.Parse("2015/4/28"))}), _
New InputManCell.ListItem(New InputManCell.SubItem() {
New InputManCell.SubItem(type1), New InputManCell.SubItem("DDD"), New InputManCell.SubItem(DateTime.Parse("2015/5/28"))}) _
})
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcComboBoxCell1})
' FindObjectメソッドを使って検索
Dim matchedItem As InputManCell.MatchedComboItemCollection
Dim item As InputManCell.ListItem
matchedItem = DirectCast(GcMultiRow1(0, 0), InputManCell.GcComboBoxCell).FindObject(DateTime.Parse("2012/10/29"), 2)
For Each item In matchedItem
' 検索結果をデバッグウィンドウに表示します。
System.Console.WriteLine(item.SubItems(1).Value.ToString())
Next
using GrapeCity.Win.MultiRow;
using InputManCell = GrapeCity.Win.MultiRow.InputMan;
Template template = new Template();
InputManCell.GcComboBoxCell gcComboBoxCell1 = new InputManCell.GcComboBoxCell();
gcComboBoxCell1.Name = "gcComboBoxCell1";
// GcComboBoxCell にカラムを追加
gcComboBoxCell1.ListColumns.AddRange(new InputManCell.ListColumn[] {
new InputManCell.ListColumn("カラム1"), new InputManCell.ListColumn("カラム2"), new InputManCell.ListColumn("カラム3") });
gcComboBoxCell1.ListColumns[0].DataDisplayType = GrapeCity.Win.Editors.DataDisplayType.Image;
Image type0 = Image.FromFile("C:\\Check0.bmp");
Image type1 = Image.FromFile("C:\\Check1.bmp");
// GcComboBoxCell に項目を追加
gcComboBoxCell1.Items.AddRange(new InputManCell.ListItem[] {
new InputManCell.ListItem(new InputManCell.SubItem[] {
new InputManCell.SubItem(type0), new InputManCell.SubItem("AAA"), new InputManCell.SubItem(DateTime.Parse("2015/2/28"))}),
new InputManCell.ListItem(new InputManCell.SubItem[] {
new InputManCell.SubItem(type1), new InputManCell.SubItem("BBB"), new InputManCell.SubItem(DateTime.Parse("2015/3/28"))}),
new InputManCell.ListItem(new InputManCell.SubItem[] {
new InputManCell.SubItem(type0), new InputManCell.SubItem("CCC"), new InputManCell.SubItem(DateTime.Parse("2015/4/28"))}),
new InputManCell.ListItem(new InputManCell.SubItem[] {
new InputManCell.SubItem(type1), new InputManCell.SubItem("DDD"), new InputManCell.SubItem(DateTime.Parse("2015/5/28"))})
});
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcComboBoxCell1 });
// FindObjectメソッドを使って検索
InputManCell.MatchedComboItemCollection matchedItem;
matchedItem = (gcMultiRow1[0, 0] as InputManCell.GcComboBoxCell).FindObject(DateTime.Parse("2012/10/29"), 2);
foreach (InputManCell.ListItem item in matchedItem)
{
// 検索結果をデバッグウィンドウに表示します。
System.Console.WriteLine(item.SubItems[1].Value.ToString());
}
リストボックスに表示された項目はソート機能により昇順または降順に並び変えることが可能です。項目を並び変えるにはListSortColumnIndexプロパティを使用してソートの基準となるカラムをインデックスで定義します。
 |
ソート機能は、GcComboBoxCellがデータソースに接続している場合には無効となります。 |
ソートの方法(昇順または降順)を設定するには、カラムのSortOrderプロパティを使用します。SortOrderは、System.Windows.Forms.SortOrder型のプロパティです。
SortOrderの値 |
説明 |
None |
ソートなし |
Ascending |
昇順 |
Descending |
降順 |
次のサンプルコードは、先頭のカラムを基準に昇順でソートする例です。
Imports GrapeCity.Win.Editors
' リストボックスにカラムを追加
GcComboBox1.ListColumns.AddRange(New ListColumn() {New ListColumn("カラム1"), New ListColumn("カラム2")})
' リストボックスに項目を追加
GcComboBox1.Items.AddRange(New ListItem() { _
New ListItem(New SubItem(){New SubItem("BBB"), New SubItem("ううう")}), _
New ListItem(New SubItem(){New SubItem("CCC"), New SubItem("あああ")}), _
New ListItem(New SubItem(){New SubItem("AAA"), New SubItem("いいい")}) _
})
' ソートの基準をカラム1に指定し、ソート方法を昇順に設定
GcComboBox1.ListSortColumnIndex = 0
GcComboBox1.ListColumns(0).SortOrder = SortOrder.Ascending
using GrapeCity.Win.Editors;
// リストボックスにカラムを追加
gcComboBox1.ListColumns.AddRange(new ListColumn[] {new ListColumn("カラム1"), new ListColumn("カラム2")});
// リストボックスに項目を追加
gcComboBox1.Items.AddRange(new ListItem[] {
new ListItem(new SubItem[]{new SubItem("BBB"), new SubItem("ううう")}),
new ListItem(new SubItem[]{new SubItem("CCC"), new SubItem("あああ")}),
new ListItem(new SubItem[]{new SubItem("AAA"), new SubItem("いいい")})
});
// ソートの基準をカラム1に指定し、ソート方法を昇順に設定
gcComboBox1.ListSortColumnIndex = 0;
gcComboBox1.ListColumns[0].SortOrder = SortOrder.Ascending;

(図) 上記サンプルコードを適用したセル
ヘッダに用意されたソート機能を使用すれば、アプリケーション実行時にユーザーが動的にソートを行うこともできます。ユーザーにソートを許可するには、ListHeaderクラスのヘッダのClickableプロパティをTrueに設定します。
ClickableプロパティをTrueに設定するとヘッダをクリックすることで、クリックしたカラムの内容で項目がソートされます。ヘッダをクリックする毎に並び替えが昇順と降順で切り替わります。項目が昇順でソートされているか、降順でソートされているかは、ヘッダに表示されたソートインジケータの向きで判別することができます。
次のサンプルコードは、ヘッダでのソートを許可する例です。
Imports GrapeCity.Win.MultiRow
Imports InputManCell = GrapeCity.Win.MultiRow.InputMan
Dim GcComboBoxCell1 = New InputManCell.GcComboBoxCell()
' リストボックスにカラムを追加
GcComboBoxCell1.ListColumns.AddRange(New InputManCell.ListColumn() {New InputManCell.ListColumn("カラム1"), New InputManCell.ListColumn("カラム2")})
' リストボックスに項目を追加
GcComboBoxCell1.Items.AddRange(New InputManCell.ListItem() { _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("BBB"), New InputManCell.SubItem("ううう")}), _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("CCC"), New InputManCell.SubItem("あああ")}), _
New InputManCell.ListItem(New InputManCell.SubItem() {New InputManCell.SubItem("AAA"), New InputManCell.SubItem("いいい")}) _
})
' ヘッダをクリックできるように設定
GcComboBoxCell1.ListColumns(0).Header.Clickable = True
GcComboBoxCell1.ListColumns(1).Header.Clickable = True
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {GcComboBoxCell1})
using GrapeCity.Win.MultiRow;
using InputManCell = GrapeCity.Win.MultiRow.InputMan;
InputManCell.GcComboBoxCell gcComboBoxCell1 = new InputManCell.GcComboBoxCell();
// リストボックスにカラムを追加
gcComboBoxCell1.ListColumns.AddRange(new InputManCell.ListColumn[] { new InputManCell.ListColumn("カラム1"), new InputManCell.ListColumn("カラム2") });
// リストボックスに項目を追加
gcComboBoxCell1.Items.AddRange(new InputManCell.ListItem[] {
new InputManCell.ListItem(new InputManCell.SubItem[]{new InputManCell.SubItem("BBB"), new InputManCell.SubItem("ううう")}),
new InputManCell.ListItem(new InputManCell.SubItem[]{new InputManCell.SubItem("CCC"), new InputManCell.SubItem("あああ")}),
new InputManCell.ListItem(new InputManCell.SubItem[]{new InputManCell.SubItem("AAA"), new InputManCell.SubItem("いいい")})
});
// ヘッダをクリックできるように設定
gcComboBoxCell1.ListColumns[0].Header.Clickable = true;
gcComboBoxCell1.ListColumns[1].Header.Clickable = true;
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { gcComboBoxCell1 });