Прочитать на английском

Поделиться через


SearchDirectionHint Перечисление

Определение

Предоставляет подсказку направления для поиска ListViewItem.

C#
public enum SearchDirectionHint
Наследование
SearchDirectionHint

Поля

Имя Значение Описание
Down 40

Под текущим элементом.

Left 37

Слева от текущего элемента.

Right 39

Справа от текущего элемента.

Up 38

Над текущим элементом.

Примеры

В следующем примере кода показано, как использовать перечисление SearchDirectionHint . Чтобы выполнить этот пример, вставьте следующий код в Форму Windows Form и вызовите InitializeLocationSearchListView из конструктора формы или Load метода обработки событий.

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 и ListViewItem , а также классом SearchForVirtualItemEventArgs . Определение ближайшего элемента в элементе 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