次の方法で共有


ListBox.MultiColumn プロパティ

ListBox が複数列をサポートするかどうかを示す値を取得または設定します。

Public Property MultiColumn As Boolean
[C#]
public bool MultiColumn {get; set;}
[C++]
public: __property bool get_MultiColumn();public: __property void set_MultiColumn(bool);
[JScript]
public function get MultiColumn() : Boolean;public function set MultiColumn(Boolean);

プロパティ値

リスト ボックスが複数列をサポートする場合は true 。それ以外の場合は false 。既定値は false です。

例外

例外の種類 条件
ArgumentException 複数列の ListBox の高さは可変にできません。

解説

複数列のリスト ボックスでは、必要に応じた列数に項目が配置されるため、垂直方向のスクロールが不要になります。ユーザーは、現在表示されていない列に移動する場合はキーボードを使用できます。水平スクロール バーを表示して、 ListBox 内の表示領域に現在表示されていない列にスクロールできるようにするには、 HorizontalScrollbar プロパティを true に設定します。 ColumnWidth プロパティの値によって各列の幅が決まります。

使用例

[Visual Basic, C#, C++] ColumnWidth プロパティと MultiColumn プロパティを使用して、複数の列に項目を表示する ListBox コントロールを作成する方法を次の例に示します。この例は、listBox1 という名前の ListBox コントロールがフォームに追加されていることを前提にしています。

 
Private Sub SetupMyMultiColumn()
   Dim x As Integer
   ' Add items to the ListBox.
   For x = 0 To 50
      ListBox1.Items.Add("Items " + x.ToString())
   Next x
   ' Display items in columns.
   ListBox1.MultiColumn = True
   ' Determine the width of the items in the list to get the best column width setting.
   Dim width As Integer = CInt(ListBox1.CreateGraphics().MeasureString(ListBox1.Items(ListBox1.Items.Count - 1).ToString(), _
      ListBox1.Font).Width)
   ' Set the column width based on the width of each item in the list.
   ListBox1.ColumnWidth = width
End Sub

[C#] 
private void SetupMyMultiColumn()
{
   // Add items to the ListBox.
   for (int x = 0; x < 50; x++)
   {
      listBox1.Items.Add("Items " + x.ToString());
   }
   // Display items in columns.
   listBox1.MultiColumn = true;
   // Determine the width of the items in the list to get the best column width setting.
   int width = (int) listBox1.CreateGraphics().MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),
      listBox1.Font).Width;
   // Set the column width based on the width of each item in the list.
   listBox1.ColumnWidth = width;
}

[C++] 
private:
   void SetupMyMultiColumn()
   {
      // Add items to the ListBox.
      for (int x = 0; x < 50; x++)
      {
         listBox1->Items->Add(String::Format( S"Items {0}", __box(x)));
      }
      // Display items in columns.
      listBox1->MultiColumn = true;
      // Determine the width of the items in the list to get the best column width setting.
      int width = (int) listBox1->CreateGraphics()->
         MeasureString(
            listBox1->Items->Item[listBox1->Items->Count -1]->ToString(),
            listBox1->Font
         ).Width;
      // Set the column width based on the width of each item in the list.
      listBox1->ColumnWidth = width;
   }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ListBox クラス | ListBox メンバ | System.Windows.Forms 名前空間 | HorizontalScrollbar | ColumnWidth