以下範例使用 TextColumn 屬性來識別提供 Text 屬性資料的清單框中資料欄位。
本範例將 ListBox 的第三欄設定為文字欄。 當你從 ListBox 選擇條目時, TextColumn 的值會顯示在 標籤中。
這個範例也示範如何使用 AddItem 方法和 List 屬性來載入多欄位的 ListBox。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定表單包含:
- 一個名為 ListBox1 的 ListBox 。
- 一個名為 TextBox1 的 TextBox 。
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 3
ListBox1.AddItem "Row 1, Col 1"
ListBox1.List(0, 1) = "Row 1, Col 2"
ListBox1.List(0, 2) = "Row 1, Col 3"
ListBox1.AddItem "Row 2, Col 1"
ListBox1.List(1, 1) = "Row 2, Col 2"
ListBox1.List(1, 2) = "Row 2, Col 3"
ListBox1.AddItem "Row 3, Col 1"
ListBox1.List(2, 1) = "Row 3, Col 2"
ListBox1.List(2, 2) = "Row 3, Col 3"
ListBox1.TextColumn = 3
End Sub
Private Sub ListBox1_Change()
TextBox1.Text = ListBox1.Text
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。