True DBGrid for WinForms
サイズ変更
> サイズ変更

True DBGrid lets you set the size of grid columns, such as set the column width, auto-adjust the column width and set a minimum or maximum column width.

Set Column Width

True DBGrid provides the DefColWidth property of C1TrueDBGrid class to set the column width across the grid.

Use the code below to set the default width of a column for True DBGrid.

C#
コードのコピー
// すべての列のデフォルト幅を設定します
c1TruedbGrid1.DefColWidth = 10;

But if you have to set a particular column's width, use the code snippet below:

C#
コードのコピー
// 列の幅を設定します。
var col = c1TruedbGrid1.Splits[0].DisplayColumns[1];
col.Width = 60;

Auto-adjust Column Width

To adjust the column width according to the text length, True DBGrid provides the AutoSize method in C1DisplayColumn class, which adjusts the width of a column to accommodate the longest visible field within that column.

Following code shows how you can auto adjust the column widths according to the text length in the WinForms True DBGrid.

C#
コードのコピー
// 列ごとに自動サイズ設定を呼び出します。
foreach (C1DisplayColumn col in c1TruedbGrid1.Splits[0].DisplayColumns)
{
    col.AutoSize();
}

Set Minimum and Maximum Column Width

True DBGrid allows you to set bounds to the column width by using the MinWidth property in C1DisplayColumn class, which gets or sets the minimum width a column can be resized to when in the C1.Win.TrueDBGrid.C1TrueDBGrid.SpringMode.

Specify the bounds of column width in the WinForms True DBGrid using the code below.

C#
コードのコピー
// SpringModeで使用する列の最小幅を設定します
foreach (C1DisplayColumn column in c1TruedbGrid1.Splits[0].DisplayColumns)
{
    column.MinWidth = 20; 
}

In this case, as mentioned above, the Spring mode should be enabled using the SpringMode property of C1TrueDBGrid class, which gets or sets a value that determines how columns will resize when the grid gets resized.

The code snippet below depicts enabling or disabling SPringMode using a checkbox (named 'chckSpring').

C#
コードのコピー
private void chckSpring_CheckedChanged(object sender, EventArgs e)
{
    //SpringModeを有効/無効にします。
    c1TruedbGrid1.SpringMode = chckSpring.Checked;
}