Share via


HOW TO:使用 Windows Form ListView 控制項以資料行顯示子項目

更新:2007 年 11 月

Windows Form ListView 控制項在 Details 檢視中可以顯示各項目的其他文字或子項目。第一資料行顯示項目文字,例如員工編號。第二、第三和後續資料行顯示第一、第二和後續相關子項目。

若要將子項目加入至清單項目

  1. 加入任何需要的資料行。由於第一個資料行會顯示項目的 Text 屬性,因此您需要的資料行數會比子項目數多一個。如需加入資料行的詳細資訊,請參閱 HOW TO:將資料行加入至 Windows Form ListView 控制項

  2. 呼叫由項目之 SubItems 屬性所傳回的集合之 Add 方法。下列程式碼範例會為清單項目設定員工姓名和部門。

    ' Adds two subitems to the first list item
    ListView1.Items(0).SubItems.Add("John Smith")
    ListView1.Items(0).SubItems.Add("Accounting")
    
    
    // Adds two subitems to the first list item.
    listView1.Items[0].SubItems.Add("John Smith");
    listView1.Items[0].SubItems.Add("Accounting");
    
    
    // Adds two subitems to the first list item.
    listView1.get_Items().get_Item(0).get_SubItems().Add("John Smith");
    listView1.get_Items().get_Item(0).get_SubItems().Add("Accounting");
    
    

請參閱

工作

HOW TO:使用 Windows Form ListView 控制項加入和移除項目

HOW TO:將資料行加入至 Windows Form ListView 控制項

HOW TO:顯示 Windows Form ListView 控制項的圖示

HOW TO:將自訂資訊加入 TreeView 或 ListView 控制項 (Windows Form)

參考

ListView 控制項概觀 (Windows Form)