ListBox 实现快速查询(C#)

kuangshazi515 2010-10-04 10:45:46

文本框中输入内容,listbox快速查询定位。
...全文
261 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuangshazi515 2010-10-05
  • 打赏
  • 举报
回复
如何实现模糊查询呢?
kuangshazi515 2010-10-05
  • 打赏
  • 举报
回复
C# 复制代码
private void FindMySpecificString(string searchString)
{
// Ensure we have a proper string to search for.
if (searchString != string.Empty)
{
// Find the item in the list and store the index to the item.
int index = listBox1.FindStringExact(searchString);
// Determine if a valid index is returned. Select the item if it is valid.
if (index != ListBox.NoMatches)
listBox1.SetSelected(index,true);
else
MessageBox.Show("The search string did not find any items in the ListBox that exactly match the specified search string");
}
}
wuyq11 2010-10-04
  • 打赏
  • 举报
回复
int index = listBox1.FindStringExact("");
xuld 2010-10-04
  • 打赏
  • 举报
回复
string s = textBox1.Text;
char c = s.Length > 0 ? '\0' : s[0];

foreach(Control item in listBox1.Items){
string f = item.Text;
if(f[0] == c && f.StartWith(s)) {
Select(item);
break;
}


}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧