閱讀英文

共用方式為


SearchDirectionHint 列舉

定義

提供何處搜尋 ListViewItem 的方向提示。

C#
public enum SearchDirectionHint
繼承
SearchDirectionHint

欄位

名稱 Description
Down 40

目前項目的下方。

Left 37

目前項目的左邊。

Right 39

目前項目的右邊。

Up 38

目前項目的上方。

範例

下列程式碼範例示範如何使用 SearchDirectionHint 列舉。 若要執行此範例,請將下列程式碼貼到 Windows Form 中,並從表單的建構函式或 Load 事件處理方法呼叫 InitializeLocationSearchListView

C#
ListView iconListView = new ListView();
TextBox previousItemBox = new TextBox();

private void InitializeLocationSearchListView()
{
    previousItemBox.Location = new Point(150, 20);

    // Create an image list for the icon ListView.
    iconListView.LargeImageList = new ImageList();
    iconListView.Height = 400;
    
    // Add an image to the ListView large icon list.
    iconListView.LargeImageList.Images.Add(
        new Bitmap(typeof(Control), "Edit.bmp"));

    // Set the view to large icon and add some items with the image
    // in the image list.
    iconListView.View = View.LargeIcon;
    iconListView.Items.AddRange(new ListViewItem[]{
        new ListViewItem("Amy Alberts", 0), 
        new ListViewItem("Amy Recker", 0), 
        new ListViewItem("Erin Hagens", 0), 
        new ListViewItem("Barry Johnson", 0), 
        new ListViewItem("Jay Hamlin", 0), 
        new ListViewItem("Brian Valentine", 0), 
        new ListViewItem("Brian Welker", 0), 
        new ListViewItem("Daniel Weisman", 0) });
    this.Controls.Add(iconListView);
    this.Controls.Add(previousItemBox);

    // Handle the MouseDown event to capture user input.
   iconListView.MouseDown +=
       new MouseEventHandler(iconListView_MouseDown);
    //iconListView.MouseWheel += new MouseEventHandler(iconListView_MouseWheel);   
}

void iconListView_MouseDown(object sender, MouseEventArgs e)
{
    
    // Find the an item above where the user clicked.
    ListViewItem foundItem =
        iconListView.FindNearestItem(SearchDirectionHint.Up, e.X, e.Y);

    // Display the results in a textbox..
    if (foundItem != null)
        previousItemBox.Text = foundItem.Text;
    else
        previousItemBox.Text = "No item found";
}

備註

這個列舉是由 FindNearestItem 和 類別中 ListView 的方法以及 類別使用 SearchForVirtualItemEventArgsListViewItem 。 識別控制項中 ListView 最接近的專案可能會因應用程式執行所在的作業系統而有所不同;因此,搜尋方向是提示,而不是結果的絕對保證。

適用於

產品 版本
.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