Leggere in inglese

Condividi tramite


SearchDirectionHint Enumerazione

Definizione

Fornisce un suggerimento sulla direzione in cui cercare un oggetto ListViewItem.

C#
public enum SearchDirectionHint
Ereditarietà
SearchDirectionHint

Campi

Nome Valore Descrizione
Down 40

Sotto all'elemento corrente.

Left 37

Alla sinistra dell'elemento corrente.

Right 39

Alla destra dell'elemento corrente.

Up 38

Sopra l'elemento corrente.

Esempio

Nell'esempio di codice seguente viene illustrato come usare l'enumerazione SearchDirectionHint . Per eseguire questo esempio, incollare il codice seguente in un Windows Form e chiamare InitializeLocationSearchListView dal costruttore del modulo o Load dal metodo di gestione degli eventi.

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

Commenti

Questa enumerazione viene usata dai FindNearestItem metodi nelle ListView classi e, ListViewItem oltre alla SearchForVirtualItemEventArgs classe . L'identificazione dell'elemento più vicino in un ListView controllo può variare a seconda del sistema operativo in cui l'applicazione è in esecuzione. Pertanto, la direzione di ricerca è un hint e non una garanzia assoluta dei risultati.

Si applica a

Prodotto Versioni
.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