閱讀英文

共用方式為


ListViewItemStates 列舉

定義

定義表示 ListViewItem 可能狀態的常數。

此列舉支援其成員值的位元組合。

C#
[System.Flags]
public enum ListViewItemStates
繼承
ListViewItemStates
屬性

欄位

名稱 Description
Checked 8

已選取這個項目。

Default 32

這個項目處於預設狀態。

Focused 16

項目已取得焦點。

Grayed 2

項目已停用。

Hot 64

項目目前位在滑鼠指標之下。

Indeterminate 256

項目處於未定狀態。

Marked 128

這個項目已標示。

Selected 1

這個項目已選取。

ShowKeyboardCues 512

項目應指示鍵盤快速鍵。

範例

下列範例示範如何為 ListView 控制項提供自訂繪圖。 範例 ListView 中的 控制項具有漸層背景。 負值的子專案具有紅色前景和黑色背景。

事件的處理常式 ListView.DrawItem 會繪製整個專案的背景,以及資料行標頭資料列的背景。 事件的處理常式 ListView.DrawSubItem 會繪製文字值,以及具有負值的子專案的文字和背景。

ContextMenu元件提供在詳細資料檢視與清單之間切換的方法。 在清單檢視中,只會 ListView.DrawItem 引發 事件。 在此情況下,會在事件處理常式中 ListView.DrawItem 繪製文字和背景。

如需完整的範例,請參閱 ListView.OwnerDraw 參考主題。

C#
// Draws the backgrounds for entire ListView items.
private void listView1_DrawItem(object sender,
    DrawListViewItemEventArgs e)
{
    if ((e.State & ListViewItemStates.Selected) != 0)
    {
        // Draw the background and focus rectangle for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
        e.DrawFocusRectangle();
    }
    else
    {
        // Draw the background for an unselected item.
        using (LinearGradientBrush brush =
            new LinearGradientBrush(e.Bounds, Color.Orange,
            Color.Maroon, LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(brush, e.Bounds);
        }
    }

    // Draw the item text for views other than the Details view.
    if (listView1.View != View.Details)
    {
        e.DrawText();
    }
}

備註

DrawListViewSubItemEventArgs.ItemState 屬性會 DrawListViewItemEventArgs.State 使用此列舉。 如需詳細資訊,請參閱 ListView.DrawItemListView.DrawSubItem 事件。

適用於

產品 版本
.NET Framework 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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱