Export (0) Print
Expand All
Expand Minimize

SearchDirectionHint Enumeration

Provides a directional hint of where to search for a ListViewItem.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public enum SearchDirectionHint

Member nameDescription
UpAbove the current item.
DownBelow the current item.
LeftTo the left of the current item
RightTo the right of the current item.

This enumeration is used by the FindNearestItem methods in the ListView and ListViewItem classes, as well as by the SearchForVirtualItemEventArgs class. Identifying the nearest item in a ListView control can vary depending on the operating system the application is running on; therefore, the search direction is a hint, and not an absolute guarantee of results.

The following code example demonstrates how to use the SearchDirectionHint enumeration. To run this example, paste the following code into a Windows Form and call InitializeLocationSearchListView from the form's constructor or Load event-handling method.

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";
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft