SearchDirectionHint Enum
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Ger en riktad ledtråd om var du ska söka efter en ListViewItem.
public enum class SearchDirectionHint
public enum SearchDirectionHint
type SearchDirectionHint =
Public Enum SearchDirectionHint
- Arv
Fält
| Name | Värde | Description |
|---|---|---|
| Left | 37 | Till vänster om det aktuella objektet. |
| Up | 38 | Ovanför det aktuella objektet. |
| Right | 39 | Till höger om det aktuella objektet. |
| Down | 40 | Under det aktuella objektet. |
Exempel
Följande kodexempel visar hur du använder SearchDirectionHint uppräkningen. Om du vill köra det här exemplet klistrar du in följande kod i ett Windows-formulär och anropar InitializeLocationSearchListView från formulärets konstruktor eller Load händelsehanteringsmetod.
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
Kommentarer
Den här uppräkningen används av FindNearestItem metoderna i klasserna ListView och ListViewItem samt av SearchForVirtualItemEventArgs klassen. Att identifiera närmaste objekt i en ListView kontroll kan variera beroende på vilket operativsystem programmet körs på. Därför är sökriktningen ett tips och inte en absolut garanti för resultat.