True DBGrid for WinForms
スプリットのサイズ変更とスケーリング
スプリットの使用方法 > スプリットのサイズ変更とスケーリング

True DBGrid for WinForms では、個別のスプリットのサイズとスケーリングを完全に制御できます。グリッドの正確な幅や高さを設定したり、列数や行数を固定したり、他のスプリットに対する比率でサイズを調整することができます。True DBGrid for WinForms をはじめて使用する場合でも、概要を覚えるだけでさまざまな方法でスプリットを使用できます。

実行時、Split オブジェクトの実際のサイズは、その SplitSize プロパティと SplitSizeMode プロパティによって決まります。SplitSizeMode プロパティは測定の単位を指定します。SplitSizeプロパティは単位数を指定します。True DBGrid for WinForms はスプリットの3つのサイズ変更モードをサポートしており、これは、SplitSizeMode プロパティの設定によって決定されます。

プロパティ 説明
SizeModeEnum.Scalable 他のスプリットに対して相対的に幅を指定する。
SizeModeEnum.Exact コンテナの座標で固定幅を指定する。
SizeModeEnum.NumberofColumns 固定列数を指定する。

スケーラブルなスプリットでは、SplitSize プロパティの値を使用して、スプリットが占めるスペースの割合が決定されます。その割合は、スケーラブルなスプリットの SplitSize 値を他のすべてのスケーラブルなスプリットの SplitSize 値の合計で割って求められます。つまり、それぞれのスケーラブルなスプリットの SplitSize プロパティを分子、スケーラブルなスプリットのサイズ合計を分母と考えることができます。スケーラブルなスプリットは、スケーラブルでないスプリットに割り当てられたスペースの残りのスペースを分け合います。デフォルトでは、すべてのスプリットがスケーラブルなので、グリッド表示領域全体を分け合います。グリッドに1つしかスプリットがない場合、SplitSizeMode は、常に Scalable です。

固定幅のスプリットでは、SplitSize プロパティの値を使用して、コンテナの座標における固定幅が指定されます。固定幅のスプリットでは、グリッドの水平境界内に収まらない部分は切り捨てられます。グリッドに1つしかスプリットがない場合、このモードは適用できません。

固定列数のスプリットでは、SplitSize プロパティを使用して、スプリット内に常に表示される列数が正確に指定されます。このスプリットでは、(コードまたはユーザーの操作によって)表示列がサイズ変更されたり、スプリット内の列が水平にスクロールされて表示列の幅が変化した場合に、グリッド全体が自動的に再設定されます。このモードは、主に水平方向にスクロールされない固定列を作成するために使用されますが、他にもさまざまな目的で使用できます。グリッドに1つしかスプリットがない場合、このモードは適用できません。

グリッドにスプリットが1つしかない(デフォルト)場合、スプリットはグリッドの幅全体に広がり、SplitSizeMode プロパティは常に Scalable に、SplitSize プロパティは常に 1 になります。スプリットが1つしかない場合は、これらのプロパティを設定しても何も効果はありません。複数のスプリットがあるときに、1つを除いてすべてを削除すると、残ったスプリットの SplitSizeMode プロパティおよび SplitSize プロパティは、それぞれ自動的に 0 および 1 に戻ります。

デフォルトでは、新しく作成したスプリットの SplitSizeMode プロパティは SizeModeEnum.Scalableに、SplitSize プロパティは1に設定されます。たとえば、次のコードで2つのスプリットを追加して作成するとします。

C#
コードのコピー
// 左側にスプリットを作成します。
this.c1TrueDBGrid1.InsertHorizontalSplit(0);

// 別のスプリットを作成します。
this.c1TrueDBGrid1.InsertHorizontalSplit(0);

これらのグリッドは、次のように表示されます。

各スプリットがグリッド領域のそれぞれ1/3ずつを占めることがわかります。これは、3つのスケーラブルなスプリットがあり、それぞれの SplitSize が1だからです。次のように、スプリットのサイズをそれぞれ1、2、および3に変更するとします。

C#
コードのコピー
// 相対サイズを1に変更します。
this.c1TrueDBGrid1.Splits[0].SplitSize = 1;

// 相対サイズを2に変更します。
this.c1TrueDBGrid1.Splits[1].SplitSize = 2;

// 相対サイズを3に変更します。
this.c1TrueDBGrid1.Splits[2].SplitSize = 3;

これらのグリッドは、次のように表示されます。

スプリットのサイズの合計が6(1+2+3)なので、各スプリットのサイズは、その SplitSize プロパティの値を分子、6を分母とする分数の割合になります。

When a split's SplitSizeMode is set to SizeModeEnum.Exact, that split receives space before the other splits. This behavior is somewhat more complex, but understanding how scalable splits work is helpful. For example, assume that splits are set in the following way:

C#
コードのコピー
this.c1TrueDBGrid1.Splits[0].SplitSizeMode = C1.Win.C1TrueDBGrid.SizeModeEnum.Scalable;
this.c1TrueDBGrid1.Splits[0].SplitSize = 1;

this.c1TrueDBGrid1.Splits[1].SplitSizeMode = C1.Win.C1TrueDBGrid.SizeModeEnum.Exact;
this.c1TrueDBGrid1.Splits[1].SplitSize = 250;

this.c1TrueDBGrid1.Splits[2].SplitSizeMode = C1.Win.C1TrueDBGrid.SizeModeEnum.Scalable;
this.c1TrueDBGrid1.Splits[2].SplitSize = 2;

After configuring the splits in this way, the resulting grid display will look like this.

The fixed-size split in the middle (Split1) is configured to exactly 250 pixels, and the remaining splits compete for the space remaining in the grid. Since the remaining splits are both scalable splits, they divide the remaining space among themselves according to the percentages calculated using their SplitSize property values. So, the leftmost split occupies 1/3 of the remaining space, and the rightmost split occupies 2/3.

Splits with SplitSizeMode set to SizeModeEnum.NumberOfColumns behave almost identically to exact splits, except their size is determined by the width of an integral number of columns. The width, however, is dynamic, so resizing the columns or scrolling so that different columns are in view will cause the entire grid to reconfigure itself.

Avoid creating a grid with no scalable splits. Although True DBGrid for WinForms handles this situation, it is difficult to work with a grid configured in this way. For example, if no splits are scalable, all splits will have an exact size, which may not fill the entire horizontal width of the grid. If the total width of the splits is too short, True DBGrid for WinForms displays a "null-zone" where there are no splits. If the total width of the splits is wider than the grid, then True DBGrid for WinForms will show only the separator lines for the splits that cannot be shown.