我无法通过 ListView 扫描以找到与给定字符串匹配的子项。这是我的代码:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
string date = datePicker.Value.ToShortDateString();
int count = Program.booker.listView.Items.Count;
for (int i = 0; i < 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 for " + date, "Alert");
}
}
}
ListView 位于 Booker 表单上,我从 Filter 类访问它。我想在整个 ListView 中搜索与我的日期字符串匹配的任何项目。谢谢!