gpt4 book ai didi

c# - 尝试在 ListView 中搜索与字符串匹配的子项

转载 作者:行者123 更新时间:2023-11-30 15:33:03 26 4
gpt4 key购买 nike

我无法扫描 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 中搜索与我的日期字符串匹配的任何项目。谢谢!

最佳答案

您可以使用 FindItemWithText方法。

ListViewItem searchItem = null;
int index = 0;
do
{
if (index < Program.booker.listView.Items.Count)
{
//true = search subitems
//last false param = no partial matches (remove if you 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);

关于c# - 尝试在 ListView 中搜索与字符串匹配的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17974592/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com