View 列舉

定義

指定如何在 ListView 控制項中顯示清單項目。

C#
public enum View
繼承

欄位

Details 1

每個項目會出現在單獨的一行上,且包含每個項目排列於欄位中的詳細資訊。 最左方的欄包含小圖示和標籤 (Label),且後續的欄包含由應用程式所指定的子項目。 欄位會顯示可顯示欄位標題的標頭。 使用者可以在執行階段調整每個欄的大小。

LargeIcon 0

每個項目顯示成下方附有標籤的全螢幕圖示。

List 3

每一個項目顯示成右方附有標籤的小圖示。 項目以不具有欄位標頭的方式排列於欄中。

SmallIcon 2

每一個項目顯示成右方附有標籤的小圖示。

Tile 4

每個項目都會顯示為大小完整的圖示,而且會在其右邊出現項目標籤和子項目資訊。 出現的子項目資訊是由應用程式來指定。 這個檢視只適用於 Windows XP 和 Windows Server 2003 系列。 在舊版作業系統上,會略過這個值,且 ListView 控制項會顯示在 LargeIcon 檢視中。

範例

下列程式碼範例示範如何將 ListView.View 屬性設定為其中 View 一個列舉值。 若要執行此範例,請將下列程式碼貼到表單中,並在表單的建構函式或 Load 方法中呼叫 InitializeListView 方法。

C#

// Declare the Listview object.
internal System.Windows.Forms.ListView myListView;

// Initialize the ListView object with subitems of a different
// style than the default styles for the ListView.
private void InitializeListView()
{

    // Set the Location, View and Width properties for the 
    // ListView object. 
    myListView = new ListView();
    myListView.Location = new System.Drawing.Point(20, 20);
    myListView.Width = 250;

    // The View property must be set to Details for the 
    // subitems to be visible.
    myListView.View = View.Details;
    
    // Each SubItem object requires a column, so add three columns.
    this.myListView.Columns.Add("Key", 50, HorizontalAlignment.Left);
    this.myListView.Columns.Add("A", 100, HorizontalAlignment.Left);
    this.myListView.Columns.Add("B", 100, HorizontalAlignment.Left);

    // Add a ListItem object to the ListView.
    ListViewItem entryListItem = myListView.Items.Add("Items");

    // Set UseItemStyleForSubItems property to false to change 
    // look of subitems.
    entryListItem.UseItemStyleForSubItems = false;

    // Add the expense subitem.
    ListViewItem.ListViewSubItem expenseItem = 
        entryListItem.SubItems.Add("Expense");

    // Change the expenseItem object's color and font.
    expenseItem.ForeColor = System.Drawing.Color.Red;
    expenseItem.Font = new System.Drawing.Font(
        "Arial", 10, System.Drawing.FontStyle.Italic);

    // Add a subitem called revenueItem 
    ListViewItem.ListViewSubItem revenueItem = 
        entryListItem.SubItems.Add("Revenue");

    // Change the revenueItem object's color and font.
    revenueItem.ForeColor = System.Drawing.Color.Blue;
    revenueItem.Font = new System.Drawing.Font(
        "Times New Roman", 10, System.Drawing.FontStyle.Bold);

    // Add the ListView to the form.
    this.Controls.Add(this.myListView);
}

備註

使用這個列舉的成員來設定 View 控制項的 ListView 屬性值。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另請參閱