GrapeCity CalendarGrid for Windows Forms 2.0J
リストボックスの使い方(CalendarGcComboBoxCellType)

カラムの設定

CalendarGcComboBoxCellType.ListColumnsプロパティを使用します。

CalendarGcComboBoxCellTypeのリストボックスでは、ヘッダと項目に複数のカラム(列)を持つことができます。表示できるカラム数に制限はありません。

カラムを設定するには、ListColumnsプロパティが参照するListColumnCollectionを使用します。ListColumnCollectionは、リストの個々のカラムを表すListColumnオブジェクトを保持するコレクションです。

カラムの追加

カラムを追加するには、デザイナのプロパティウィンドウのListColumnsプロパティから開かれる「カラムの編集」ダイアログボックスで[追加]ボタンをクリックします。カラムを1つ追加すると、CalendarGcComboBoxCellTypeのヘッダと項目には列が1つ追加されます。
コードからカラムを追加するには、ListColumnCollectionのAddメソッドまたはAddRangeメソッドを使用します。

次は、Addメソッドを使用してカラムを1つ追加するサンプルコードです。ここではカラムの名前(ヘッダに表示されるテキスト)を指定してカラムを追加しています。

Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim GcComboBoxCellType As New InputManCell.CalendarGcComboBoxCellType()
GcComboBoxCellType.ListColumns.Add(New InputManCell.ListColumn("カラム1"))

GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = GcComboBoxCellType
GcCalendarGrid1.ScrollIntoView(today)
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;
var gcComboBoxCellType = new InputManCell.CalendarGcComboBoxCellType();
gcComboBoxCellType.ListColumns.Add(new InputManCell.ListColumn("カラム1"));

gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcComboBoxCellType;
gcCalendarGrid1.ScrollIntoView(today);

カラムの設定内容

カラム(ListColumn)は、主に次のプロパティを設定できます。

カラムの既定値

カラムの各設定は、既定値を設定しておくことによって、繰り返し設定を変更する手間を省略できます。カラムの既定値は、デザイナのプロパティウィンドウのListDefaultColumnプロパティから開かれる「カラムの既定値の設定」ダイアログで編集することができます。

デフォルトカラムは、ListDefaultColumnプロパティで設定します。ListDefaultColumnは、DefaultListColumn型のオブジェクトで以下のプロパティを設定することができます。

カラムの削除

CalendarGcComboBoxCellTypeからカラムを削除するには、デザイナのプロパティウィンドウのListColumnsプロパティから開かれる「カラムの編集」ダイアログで、削除したいカラムを選択して[削除]ボタンをクリックします。カラムを1つ削除すると、CalendarGcComboBoxCellTypeのヘッダと項目から選択しカラムが1つ削除されます。
コードからカラムを削除するには、ListColumnCollectionのRemoveメソッドまたはRemoveAtメソッドを使用します。

次のコードは、RemoveAtメソッドを使用して先頭のカラムを1つ削除するサンプルコードです。
このサンプルでは、テンプレートのRowセクションにCalendarGcComboBoxCellType が配置されていることを前提とします。

Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim cellPos As CalendarCellPosition = GcCalendarGrid1.CurrentCellPosition

Dim GcComboBoxCellType As InputManCell.CalendarGcComboBoxCellType = _
    DirectCast(GcCalendarGrid1.Content(cellPos.Date).Rows(cellPos.RowIndex).Cells(cellPos.ColumnIndex).CellType, InputManCell.CalendarGcComboBoxCellType)
GcComboBoxCellType.ListColumns.RemoveAt(0)

GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = GcComboBoxCellType
GcCalendarGrid1.ScrollIntoView(today)
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;
CalendarCellPosition cellPos = gcCalendarGrid1.CurrentCellPosition;

InputManCell.CalendarGcComboBoxCellType gcComboBoxCellType =
    (gcCalendarGrid1.Content[cellPos.Date].Rows[cellPos.RowIndex].Cells[cellPos.ColumnIndex].CellType as InputManCell.CalendarGcComboBoxCellType);
gcComboBoxCellType.ListColumns.RemoveAt(0);

gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcComboBoxCellType;
gcCalendarGrid1.ScrollIntoView(today);

カラムのリサイズListHeader.AllowResizeプロパティをTrueに設定すると、アプリケーションの実行時にユーザーはマウス操作等でカラムのサイズを自由に変更できるようになります。
実行時にカラムのサイズ(幅)を変更するには、サイズを変更したいカラムの境界線の位置でマウスの左ボタンを押し、変更したいサイズに合わせてマウスカーソルを移動し、左ボタンを離します。


ヘッダの表示

CalendarGcComboBoxCellType.ListHeaderPaneオブジェクトのVisibleプロパティを使用します。

リストボックスにヘッダを表示するには、ListHeaderPaneプロパティが参照するListHeaderPaneオブジェクトのVisibleプロパティをTrueに設定します。ListHeaderPaneは、ヘッダ領域の全体を表すオブジェクトで、ヘッダの外観などを設定することができます。ヘッダの外観の設定方法については、「外観を変更する」を参照してください。

リストボックスにカラムが設定されるとヘッダにはカラムヘッダが表示されます。
カラムヘッダの操作は、ListColumn.Headerプロパティで行います。Headerプロパティは、ListHeader型のプロパティです。


ヘッダの設定

CalendarGcComboBoxCellType.ListColumn オブジェクトの Header プロパティを使用します。

タイトルの変更

ヘッダのタイトルを変更するには、ListHeader.Textプロパティを使用します。
以下にヘッダのテキストを変更する例を示します。次のサンプルコードでは、リストボックスに予め2つのカラムが追加されていることを前提にしています。

Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim GcComboBoxCellType As InputManCell.CalendarGcComboBoxCellType = _
    DirectCast(GcCalendarGrid1(today)(1, 0).CellType, InputManCell.CalendarGcComboBoxCellType)
GcComboBoxCellType.ListColumns(0).Header.Text = "カラム1"
GcComboBoxCellType.ListColumns(1).Header.Text = "カラム2"
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;

InputManCell.CalendarGcComboBoxCellType gcComboBoxCellType =
    (gcCalendarGrid1[today][1, 0].CellType as InputManCell.CalendarGcComboBoxCellType);
gcComboBoxCellType.ListColumns[0].Header.Text = "カラム1";
gcComboBoxCellType.ListColumns[1].Header.Text = "カラム2";

ヘッダに画像を表示する

カラムヘッダにはテキスト以外に画像を表示することができます。



画像を表示するには、ListHeader.Imageプロパティを使用します。
Imageプロパティには、表示する画像のインデックスを設定します。Imageプロパティに設定するインデックスは、セルのImageListプロパティに設定したImageListオブジェクトのImagesプロパティが参照するImageList.ImageCollectionのインデックスです。

表示された画像の位置は、ListHeader.TextAttachAlignmentプロパティで設定します。
また、画像とテキストの距離は、ListHeader.ImageTextSpaceプロパティで設定します。
以下にヘッダに画像を変更する例を示します。次のサンプルコードでは、リストボックスに予め2つのカラムが追加されていることを前提にしています。

Imports GrapeCity.Win.CalendarGrid
Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim GcComboBoxCellType As InputManCell.CalendarGcComboBoxCellType = _
    DirectCast(GcCalendarGrid1(today)(1, 0).CellType, InputManCell.CalendarGcComboBoxCellType)

' ImageListプロパティを設定
Dim iList As New ImageList()
iList.Images.Add(Image.FromFile("C:\Image1.bmp"))
iList.Images.Add(Image.FromFile("C:\Image2.bmp"))
GcComboBoxCellType.ImageList = iList

' ヘッダに画像を設定
GcComboBoxCellType.ListColumns(0).Header.Image = 0
GcComboBoxCellType.ListColumns(0).Header.TextAttachAlignment = InputManCell.AttachAlignment.LeftMiddle
GcComboBoxCellType.ListColumns(0).Header.ImageTextSpace = 3
GcComboBoxCellType.ListColumns(1).Header.Image = 1
GcComboBoxCellType.ListColumns(1).Header.TextAttachAlignment = InputManCell.AttachAlignment.LeftMiddle
GcComboBoxCellType.ListColumns(1).Header.ImageTextSpace = 3
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;

InputManCell.CalendarGcComboBoxCellType gcComboBoxCellType =
    (gcCalendarGrid1[today][1, 0].CellType as InputManCell.CalendarGcComboBoxCellType);

// ImageListプロパティを設定
ImageList iList = new ImageList();
iList.Images.Add(Image.FromFile("C:\\Image1.bmp"));
iList.Images.Add(Image.FromFile("C:\\Image2.bmp"));
gcComboBoxCellType.ImageList = iList;

// ヘッダに画像を設定
gcComboBoxCellType.ListColumns[0].Header.Image = 0;
gcComboBoxCellType.ListColumns[0].Header.TextAttachAlignment = InputManCell.AttachAlignment.LeftMiddle;
gcComboBoxCellType.ListColumns[0].Header.ImageTextSpace = 3;
gcComboBoxCellType.ListColumns[1].Header.Image = 1;
gcComboBoxCellType.ListColumns[1].Header.TextAttachAlignment = InputManCell.AttachAlignment.LeftMiddle;
gcComboBoxCellType.ListColumns[1].Header.ImageTextSpace = 3;

省略文字

ListHeader.Ellipsisプロパティを使用すると、ヘッダのテキストの長さがカラムの幅より大きいとき、省略文字を表示するかどうか設定することができます。

       


ソート

CalendarGcComboBoxCellType.ListSortColumnIndexプロパティを使用します。

リストボックスに表示された項目はソート機能により昇順または降順に並び変えることが可能です。項目を並び変えるにはListSortColumnIndexプロパティを使用してソートの基準となるカラムをインデックスで定義します。
注意 
ソート機能は、CalendarGcComboBoxCellTypeがデータソースに接続している場合には無効となります。

ソートの方法(昇順または降順)を設定するには、カラムのSortOrderプロパティを使用します。SortOrderは、System.Windows.Forms.SortOrder型のプロパティです。        

SortOrderの値 説明

SortOrder.None

ソートなし

SortOrder.Ascending

昇順

SortOrder.Descending

降順

次のサンプルコードは、先頭のカラムを基準に昇順でソートする例です。

Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim gcComboBoxCellType = New InputManCell.CalendarGcComboBoxCellType()

' リストボックスにカラムを追加
GcComboBoxCellType.ListColumns.AddRange(New InputManCell.ListColumn() {New InputManCell.ListColumn("カラム1"), New InputManCell.ListColumn("カラム2")})

' リストボックスに項目を追加
GcComboBoxCellType.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("いいい")})
 })

' ソートの基準をカラム1に指定し、ソート方法を昇順に設定
GcComboBoxCellType.ListSortColumnIndex = 0
GcComboBoxCellType.ListColumns(0).SortOrder = SortOrder.Ascending

GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = gcComboBoxCellType
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;
var gcComboBoxCellType = new InputManCell.CalendarGcComboBoxCellType();

// リストボックスにカラムを追加
gcComboBoxCellType.ListColumns.AddRange(new InputManCell.ListColumn[] { new InputManCell.ListColumn("カラム1"), new InputManCell.ListColumn("カラム2") });

// リストボックスに項目を追加
gcComboBoxCellType.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("いいい")})
});

// ソートの基準をカラム1に指定し、ソート方法を昇順に設定
gcComboBoxCellType.ListSortColumnIndex = 0;
gcComboBoxCellType.ListColumns[0].SortOrder = SortOrder.Ascending;

gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcComboBoxCellType;

(図) 上記サンプルコードを適用したセル

ヘッダに用意されたソート機能を使用すれば、アプリケーション実行時にユーザーが動的にソートを行うこともできます。ユーザーにソートを許可するには、ヘッダのClickableプロパティをTrueに設定します。
ClickableプロパティをTrueに設定するとヘッダをクリックすることで、クリックしたカラムの内容で項目がソートされます。ヘッダをクリックする毎に並び替えが昇順と降順で切り替わります。項目が昇順でソートされているか、降順でソートされているかは、ヘッダに表示されたソートインジケータの向きで判別することができます。

次のサンプルコードは、ヘッダでのソートを許可する例です。

Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim gcComboBoxCellType = New InputManCell.CalendarGcComboBoxCellType()

' リストボックスにカラムを追加
gcComboBoxCellType.ListColumns.AddRange(New InputManCell.ListColumn() {New InputManCell.ListColumn("カラム1"), New InputManCell.ListColumn("カラム2")})

' リストボックスに項目を追加
gcComboBoxCellType.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("いいい")}) _
 })

' ヘッダをクリックできるように設定
gcComboBoxCellType.ListColumns(0).Header.Clickable = True
gcComboBoxCellType.ListColumns(1).Header.Clickable = True

GcCalendarGrid1.Content(today).Rows(1).Cells(0).CellType = gcComboBoxCellType
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

var today = DateTime.Today;
var gcComboBoxCellType = new InputManCell.CalendarGcComboBoxCellType();

// リストボックスにカラムを追加
gcComboBoxCellType.ListColumns.AddRange(new InputManCell.ListColumn[] { new InputManCell.ListColumn("カラム1"), new InputManCell.ListColumn("カラム2") });
        
// リストボックスに項目を追加
gcComboBoxCellType.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("いいい")})
});

// ヘッダをクリックできるように設定
gcComboBoxCellType.ListColumns[0].Header.Clickable = true;
gcComboBoxCellType.ListColumns[1].Header.Clickable = true;

gcCalendarGrid1.Content[today].Rows[1].Cells[0].CellType = gcComboBoxCellType;


リストボックスの幅の自動調整

リストボックス(ドロップダウンウィンドウ)は、DropDown.AutoWidthプロパティを設定して幅を自動調整できます。
AutoWidthプロパティをTrueに設定すると、追加されているカラムを全て表示するようにリストボックスの幅が調整されます。

注意 
ドロップダウンウィンドウがマウスによってリサイズされた場合にはリサイズ後のサイズが保持され、プロパティの設定は無視されます。


リストボックスの高さ設定

リストボックス(ドロップダウンウィンドウ)は、次のプロパティによって高さを設定することが可能です。

プロパティの種類 説明

DropDown.Height

ドロップダウンウィンドウの高さを取得または設定します。

DropDownMaxHeight

ドロップダウンウィンドウの最大の高さを取得または設定します。

MaxDropDownItems

ドロップダウンウィンドウに表示される項目の最大数を取得または設定します。

これらのプロパティには優先度があり、高さは優先度順で設定されます。

DropDown.Height > DropDownMaxHeight > MaxDropDownItems
注意 
ドロップダウンウィンドウがマウスによってリサイズされた場合にはリサイズ後のサイズが保持され、プロパティの設定は無視されます。


参照

 

 


© 2008 GrapeCity inc. All rights reserved.