GcMultiRow.HorizontalAutoSizeModeプロパティを使用すると、列ヘッダセクション、列フッタセクションまたは行に配置されたセルのコンテンツに合わせてセルの幅を自動調整できます。
 |
- GcMultiRow.HorizontalAutoSizeModeプロパティにNone以外が設定されている場合、ヘッダ右端のダブルクリックによる列幅の自動調整は動作しません。
- GcMultiRow.HorizontalAutoSizeModeプロパティにNone以外が設定された状態でCell.PerformHorizontalAutoFitメソッドまたはCell.HorizontalResizeメソッドを実行すると、System.InvalidOperationException例外が発生します。
|
次のコードは、列ヘッダセクションに配置されたセルのコンテンツに合わせてセルの幅を自動調整します。
Imports GrapeCity.Win.MultiRow
Dim TextBoxCell1 As New TextBoxCell()
TextBoxCell1.Name = "TextBoxCell1"
Dim TextBoxCell2 As New TextBoxCell()
TextBoxCell2.Name = "TextBoxCell2"
Dim Template1 As Template = Template.CreateGridTemplate(New Cell() {TextBoxCell1, TextBoxCell2})
Template1.ColumnHeaders(0).Cells("columnHeaderCell1").Value = "Column1"
Template1.ColumnHeaders(0).Cells("columnHeaderCell2").Value = "列ヘッダ型セル2"
GcMultiRow1.Template = Template1
GcMultiRow1.RowCount = 3
GcMultiRow1.SetValue(0, "TextBoxCell1", "ABC")
GcMultiRow1.SetValue(0, "TextBoxCell2", "MultiRow for Windows Forms 8.0J")
GcMultiRow1.HorizontalAutoSizeMode = HorizontalAutoSizeMode.CellsInColumnHeader
using GrapeCity.Win.MultiRow;
TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Name = "textBoxCell1";
TextBoxCell textBoxCell2 = new TextBoxCell();
textBoxCell2.Name = "textBoxCell2";
Template template1 = Template.CreateGridTemplate(new Cell[] { textBoxCell1, textBoxCell2 });
template1.ColumnHeaders[0].Cells["columnHeaderCell1"].Value = "Column1";
template1.ColumnHeaders[0].Cells["columnHeaderCell2"].Value = "列ヘッダ型セル2";
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 3;
gcMultiRow1.SetValue(0, "textBoxCell1", "ABC");
gcMultiRow1.SetValue(0, "textBoxCell2", "MultiRow for Windows Forms 8.0J");
gcMultiRow1.HorizontalAutoSizeMode = HorizontalAutoSizeMode.CellsInColumnHeader;
複数列を選択した状態でヘッダの右端をダブルクリックすると、それぞれのセルのコンテンツに合わせてセルの幅の自動調整ができます。この動作を実現するために必要な設定は特にありません。
なお、
Template.LayoutModeプロパティにLeftToRightを設定して列モードを使用している場合、行の幅が自動調整されるため、見た目上の動作はTemplate.LayoutModeプロパティにTopToBottomを設定した場合と同じになります。
AllowUserToAutoFitColumnsプロパティをFalseに設定すると、ヘッダの右端をダブルクリックしたときに列幅を自動調整する動作を無効にできます。
GcMultiRow1.AllowUserToAutoFitColumns = False
gcMultiRow1.AllowUserToAutoFitColumns = false;
GcMultiRow.CellAutoFitPreferredSizeNeededイベントを使用して、ヘッダの右端をダブルクリックした時に自動調整されるセル幅をカスタマイズできます。
次のコードは、ヘッダの右端をダブルクリックした時に列幅を100に自動調整します。
Imports GrapeCity.Win.MultiRow
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim TextBoxCell1 As New TextBoxCell()
TextBoxCell1.Name = "TextBoxCell1"
Dim Template1 As Template = Template.CreateGridTemplate(New Cell() {TextBoxCell1})
GcMultiRow1.Template = Template1
GcMultiRow1.RowCount = 3
GcMultiRow1.SetValue(0, "TextBoxCell1", "ABC")
End Sub
Private Sub GcMultiRow1_CellAutoFitPreferredSizeNeeded(sender As Object, e As CellAutoFitPreferredSizeNeededEventArgs) Handles GcMultiRow1.CellAutoFitPreferredSizeNeeded
If e.Scope = CellScope.Row Then
Dim TextBoxCell1 = DirectCast(GcMultiRow1.Rows(e.SectionIndex).Cells(e.CellIndex), TextBoxCell)
If TextBoxCell1 IsNot Nothing AndAlso e.Direction = Orientation.Horizontal Then
e.PreferredSize = New Size(100, e.PreferredSize.Height)
End If
End If
End Sub
using GrapeCity.Win.MultiRow;
private void Form1_Load(object sender, EventArgs e)
{
TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Name = "textBoxCell1";
Template template1 = Template.CreateGridTemplate(new Cell[] { textBoxCell1 });
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 3;
gcMultiRow1.SetValue(0, "textBoxCell1", "ABC");
}
private void gcMultiRow1_CellAutoFitPreferredSizeNeeded(object sender, CellAutoFitPreferredSizeNeededEventArgs e)
{
if (e.Scope == CellScope.Row)
{
TextBoxCell textBoxCell = gcMultiRow1[e.SectionIndex, e.CellIndex] as TextBoxCell;
if (textBoxCell != null && e.Direction == Orientation.Horizontal)
{
e.PreferredSize = new Size(100, e.PreferredSize.Height);
}
}
}