SearchDirectionHint Enumeration
Provides a directional hint of where to search for a ListViewItem.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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;
TextBox^ previousItemBox;
private:
void InitializeLocationSearchListView()
{
previousItemBox = gcnew TextBox();
iconListView = gcnew ListView();
previousItemBox->Location = Point(150, 20);
// Create an image list for the icon ListView.
iconListView->SmallImageList = gcnew ImageList();
// Add an image to the ListView small icon list.
iconListView->SmallImageList->Images->Add(
gcnew Bitmap(Control::typeid, "Edit.bmp"));
// Set the view to small icon and add some items with the image
// in the image list.
iconListView->View = View::SmallIcon;
iconListView->Items->AddRange(gcnew array<ListViewItem^>{
gcnew ListViewItem("Amy Alberts", 0),
gcnew ListViewItem("Amy Recker", 0),
gcnew ListViewItem("Erin Hagens", 0),
gcnew ListViewItem("Barry Johnson", 0),
gcnew ListViewItem("Jay Hamlin", 0),
gcnew ListViewItem("Brian Valentine", 0),
gcnew ListViewItem("Brian Welker", 0),
gcnew ListViewItem("Daniel Weisman", 0) });
this->Controls->Add(iconListView);
this->Controls->Add(previousItemBox);
// Handle the MouseDown event to capture user input.
iconListView->MouseDown += gcnew MouseEventHandler(
this, &Form1::iconListView_MouseDown);
}
void iconListView_MouseDown(Object^ sender, MouseEventArgs^ e)
{
// Find the next item up from where the user clicked.
ListViewItem^ foundItem = iconListView->FindNearestItem(
SearchDirectionHint::Up, e->X, e->Y);
// Display the results in a textbox..
if (foundItem != nullptr)
{
previousItemBox->Text = foundItem->Text;
}
else
{
previousItemBox->Text = "No item found";
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.