使用组合框从数据表中搜索数据 [英] search data from data table using combobox

查看:92
本文介绍了使用组合框从数据表中搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然键入一个单词,但我想从sql表中绑定数据并希望自动出现在组合框上的列表



我的代码在这里。可以不会自动显示组合框上的数据列表。

帮助我。



  private   void  SearchItem( string  item)
{
DataSet data = new DataSet();
DataTable table = new DataTable();
data = logic.GetData_By_Desc( SearchbyProductDescription,item);
table.Rows.Clear();
table = data.Tables [ 0 ];
cboSearch.DataSource = table;
cboSearch.DisplayMember = 描述;
cboSearch.ValueMember = id;
cboSearch.DroppedDown = true ;
}
私有 void cboSearch_KeyDown( object sender,KeyEventArgs e)
{
if (e.KeyValue == 13
{
string item = cboSearch.Text;
SearchItem(item);}

}



ttds

解决方案

< blockquote>你必须使用一些不同的键而不是ENTER来提交搜索。当您按ENTER键时,ComboBox将折叠其DroppedDown列表。这就是系统行为。


while key in a word, I want to bind the data from sql table and want to automatically come out the list on combobox

My code is here.Can''t automatically show the list of data on combobox.
Help me.

 private void SearchItem(string item)
        { 
               DataSet data = new DataSet();
            DataTable table = new DataTable();
            data = logic.GetData_By_Desc("SearchbyProductDescription", item);
            table.Rows.Clear();            
            table = data.Tables[0];            
            cboSearch.DataSource = table;
            cboSearch.DisplayMember = "Description";
            cboSearch.ValueMember = "id";          
            cboSearch.DroppedDown = true;
}
private void cboSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                string item = cboSearch.Text;
                SearchItem(item);}

}


ttds

解决方案

You have to use some different key instead of ENTER for submitting the search. When you press ENTER, the ComboBox will collapse its DroppedDown list. That is system behaviour.


这篇关于使用组合框从数据表中搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆