Search function on listview
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-04-21T09:58:20Z
Indexed on
2010/04/21
10:03 UTC
Read the original article
Hit count: 307
c#
Is it possible to search a listview and restrict the items in the listview by the search criteria?
private void displayDeliveries()
{
lstDeliveryDetails.Items.Clear();
foreach (Delivery d in mainForm.myDeliveries)
{
ListViewItem item = lstDeliveryDetails.Items.Add(d.DeliveryName);
item.SubItems.Add(d.DeliveryAddress);
item.SubItems.Add(d.DeliveryDay);
item.SubItems.Add(d.DeliveryTime);
item.SubItems.Add(d.DeliveryMeal);
item.SubItems.Add(d.DeliveryInstructions);
item.SubItems.Add(d.DeliveryStatus);
}
}
At the moment that code populates the listview.
private void btnSearch_Click(object sender, EventArgs e)
{
//reset the selection and get the searched text
iDeliverySelected = -1;
string searchValue = txtSearchBox.Text;
//loop through to find the search
for (int i = 0; i < myDeliveries.Count; i++)
{
Delivery d = (Delivery)mainForm.myDeliveries[i];
if (d.DeliveryName == searchValue)
MessageBox.Show("name matched");
}
}
So far this is what I have for search, I'm struggling to take it to the next level!
Could anyone offer an ideas? Thanks
© Stack Overflow or respective owner