GrapeCity CalendarGrid for Windows Forms 2.0J
サイドボタンを設定する(CalendarGcTextBoxCellType)

CalendarGcTextBoxCellType.SideButtonsプロパティを使用します。
ここではセル内に追加可能なボタン(サイドボタン)の使用方法について解説します。


ボタンの追加と削除

セルの左右両端にはサイドボタンとして自由にボタンを配置し機能を割り付けることができます。ドロップダウンボタンには表示されるエディットウィンドウを関連付けしたり、ボタンに独自の機能を設定することができます。

セルにボタンを追加するには、SideButtonsプロパティが参照するSideButtonCollectionクラスを使用します。SideButtonCollectionクラスは、セルに追加するボタンオブジェクトのコレクションで、セルに追加可能なサイドボタンを追加、削除するためのメソッドを提供します。

セルには次の4種類のボタンオブジェクトを追加できます。

ボタンの追加や削除を行うには、デザイナのプロパティウィンドウから開かれるサイドボタン コレクション エディタから行うことができます。
また、コードでセルにボタンを追加するには、SideButtonCollectionオブジェクトのAddまたはAddRangeメソッドを使用します。

以下は、Add メソッドを使用して CalendarGcTextBoxCellType にドロップダウンボタンを追加する例です。

Imports InputManCell = GrapeCity.Win.CalendarGrid.InputMan

Dim today As DateTime = DateTime.Today
Dim GcTextBoxCellType As New InputManCell.CalendarGcTextBoxCellType()
GcTextBoxCellType.SideButtons.Add(New InputManCell.DropDownButton())

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

var today = DateTime.Today;
var gcTextBoxCellType = new InputManCell.CalendarGcTextBoxCellType();
gcTextBoxCellType.SideButtons.Add(new InputManCell.DropDownButton());

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

追加したボタンを削除するには、SideButtonCollectionクラスのRemoveメソッドまたは、RemoveAtメソッドを使用します。また、Clearメソッドでコレクションに追加されたすべてのボタンをクリアすることができます。

以下は、RemoveAtメソッドを使用してコレクションの先頭に追加されたボタンを削除する例です。

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

Dim pos As CalendarCellPosition = GcCalendarGrid1.CurrentCellPosition
Dim GcTextBoxCellType As InputManCell.CalendarGcTextBoxCellType = _
    DirectCast(GcCalendarGrid1.Content(pos.Date).Rows(pos.RowIndex).Cells(pos.ColumnIndex).CellType.Clone(), InputManCell.CalendarGcTextBoxCellType)

If GcTextBoxCellType.SideButtons.Count > 0 Then
    GcTextBoxCellType.SideButtons.RemoveAt(0)
End If

GcCalendarGrid1.Content(pos.Date).Rows(pos.RowIndex).Cells(pos.ColumnIndex).CellType = GcTextBoxCellType
using GrapeCity.Win.CalendarGrid;
using InputManCell = GrapeCity.Win.CalendarGrid.InputMan;

CalendarCellPosition pos = gcCalendarGrid1.CurrentCellPosition;
var gcTextBoxCellType =
    gcCalendarGrid1.Content[pos.Date].Rows[pos.RowIndex].Cells[pos.ColumnIndex].CellType.Clone() as InputManCell.CalendarGcTextBoxCellType;

if (gcTextBoxCellType.SideButtons.Count > 0)
{
    gcTextBoxCellType.SideButtons.RemoveAt(0);
}

gcCalendarGrid1.Content[pos.Date].Rows[pos.RowIndex].Cells[pos.ColumnIndex].CellType = gcTextBoxCellType;


デザイン機能

コントロールの機能のため、InputManCellでサポートされません。


外観の変更

各ボタンオブジェクトのPositionプロパティを使用するとボタンの表示位置を設定することができます。

それぞれの位置でのボタンの並びはコレクション内のインデックスによって決定されます。コレクション内のインデックスが小さい順に左から右へボタンが配置されます。
ボタンのサイズはセルの高さと各ボタンオブジェクトのWidthプロパティによって設定されます。

サイドボタンの背景色は各ボタンオブジェクトのBackColorプロパティで、前景色はForeColorプロパティで設定します。背景色と前景色はセルのFlatStyleプロパティがFlat、およびPopupの場合のみ有効となります。

(図) FlatStyle プロパティがFlatの場合

(図) FlatStyle プロパティがPopupの場合


プロパティによる動作の割り当て

各サイドボタンでは押されたときの動作をプロパティで割り当てることができます。

サイドボタンへのスピン動作の割り当て

SideButtonクラスはスピン動作の割り当てを設定するBehaviorプロパティを提供しますが、CalendarGcTextBoxCellTypeでは既定のスピン動作が存在しないため、設定値に関わらず無効です。

シンボルボタンへのスピン動作の割り当て

SymbolButtonクラスはスピン動作の割り当てを設定するBehaviorプロパティを提供しますが、CalendarGcTextBoxCellTypeでは既定のスピン動作が存在しないため、設定値に関わらず無効です。


参照

 

 


© 2008 GrapeCity inc. All rights reserved.