SearchDirectionHint Enumeration
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Stellt einen richtungsgerichteten Hinweis darauf bereit, wo nach einer ListViewItemgesucht werden soll.
public enum class SearchDirectionHint
public enum SearchDirectionHint
type SearchDirectionHint =
Public Enum SearchDirectionHint
- Vererbung
Felder
| Name | Wert | Beschreibung |
|---|---|---|
| Left | 37 | Links neben dem aktuellen Element. |
| Up | 38 | Über dem aktuellen Element. |
| Right | 39 | Rechts neben dem aktuellen Element. |
| Down | 40 | Unterhalb des aktuellen Elements. |
Beispiele
Im folgenden Codebeispiel wird die Verwendung der SearchDirectionHint Enumeration veranschaulicht. Um dieses Beispiel auszuführen, fügen Sie den folgenden Code in ein Windows Formular ein, und rufen Sie InitializeLocationSearchListView aus dem Konstruktor des Formulars oder Load Ereignisbehandlungsmethode auf.
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";
}
}
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";
}
Private WithEvents iconListView As New ListView()
Private previousItemBox As New TextBox()
Private Sub InitializeLocationSearchListView()
previousItemBox.Location = New Point(150, 20)
' Create an image list for the icon ListView.
iconListView.LargeImageList = New ImageList()
' Add an image to the ListView large icon list.
iconListView.LargeImageList.Images.Add(New Bitmap(GetType(Control), "Edit.bmp"))
' Set the view to large icon and add some items with the image
' in the image list.
iconListView.View = View.SmallIcon
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)})
Me.Controls.Add(iconListView)
Me.Controls.Add(previousItemBox)
End Sub
Sub iconListView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles iconListView.MouseDown
' Find the next item up from where the user clicked.
Dim foundItem As ListViewItem = _
iconListView.FindNearestItem(SearchDirectionHint.Up, e.X, e.Y)
' Display the results in a textbox.
If (foundItem IsNot Nothing) Then
previousItemBox.Text = foundItem.Text
Else
previousItemBox.Text = "No item found"
End If
End Sub
Hinweise
Diese Aufzählung wird von den Methoden in den FindNearestItemListView Und ListViewItem Klassen sowie von der SearchForVirtualItemEventArgs Klasse verwendet. Das Identifizieren des nächstgelegenen Elements in einem ListView Steuerelement kann je nach Betriebssystem variieren, auf dem die Anwendung ausgeführt wird. Daher ist die Suchrichtung ein Hinweis und keine absolute Garantie für Ergebnisse.