本文介绍了快速搜索.net(c#和vb.net)winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



i存储阵列中的一些物品(或组合框)

i想要快速搜索其中的物品。



以下代码搜索所有项目,需要多次。我想要快速搜索



string _search_items ='computer'

for(int i = 0; i< combobox.items.count ; i ++)

{

if(combobox.items [i] == _search_items)

ok;

}



如何快速访问项目而不搜索所有项目?



谢谢。

hello

i store some items in a array (or in combobox)
i wants to search an items in them fastly.

the following code search all items and it's take several times . i want have a fast search

string _search_items='computer'
for (int i=0 ; i< combobox.items.count; i++)
{
if (combobox.items[i] == _search_items)
ok;
}

how can i access to item fastly without search all items?

thanks.

推荐答案

string _search_items='computer'
for (int i=0 ; i< combobox.items.count; i++)
{
if (combobox.items[i] == _search_items)
ok; //agreed

break;
}

//or this  Try to have your combobox elements sorted like
// A B C D

Try .......


 BindingSource src = new BindingSource();
 src.DataSource = new Hashtable(); // fill it with ur data

comboBox1.DataSource = src;
 comboBox1.ValueMember = "Key";
 comboBox1.DisplayMember = "Value.DisplayName





将hastable与作为数据源的组合框绑定后,你可以找到任何0(1)项的复杂性。



After binding a hastable to your combobox as datasource, u can find any item 0(1) complexity.


这篇关于快速搜索.net(c#和vb.net)winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:01