c# - Trying to search ListView for subitems matching a string -
i'm having trouble scanning through listview locate subitem matching given string. here's code:
private void datetimepicker1_valuechanged(object sender, eventargs e) { string date = datepicker.value.toshortdatestring(); int count = program.booker.listview.items.count; (int = 0; < count; i++) { listviewitem lvi = program.booker.listview.items[i]; if (lvi.subitems.equals(date)) { messagebox.show("found!", "alert"); program.booker.listview.multiselect = true; program.booker.listview.items[i].selected = true; } else { messagebox.show("nothing found " + date, "alert"); } } }
the listview located on booker form, , i'm accessing filter class. i'd search entire listview items matching date string. thanks!
you can use finditemwithtext method.
listviewitem searchitem = null; int index = 0; { if (index < program.booker.listview.items.count) { //true = search subitems //last false param = no partial matches (remove if want partial matches) searchitem = program.booker.listview.finditemwithtext(date, true, index, false); if (searchitem != null) { index = searchitem.index + 1; //rest of code } } else searchitem =null; } while (searchitem != null);
Comments
Post a Comment