如何获取组合框下拉列表自动完成选择的ID [英] How To Get Id on combobox dropdown autocomplete selection

查看:242
本文介绍了如何获取组合框下拉列表自动完成选择的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#3.5创建一个Windows应用程序,我有一个组合框,可以让用户输入文本,当用户从自动完成列表ID中选择文本时没有选择



我的代码:

I am making a Windows application in C#3.5 and i have a combo box that will let the user type text and when user select text from autocomplete list id is not selected

my code :

cboCustomer.DropDownStyle = ComboBoxStyle.DropDown;

DataTable dt = Globale.ReturnTable("SELECT Id, [NAME] FROM ACTM WHERE (DBCR = 'D') ORDER BY [NAME]");

cboCustomer.DataSource = dt;
cboCustomer.ValueMember = "Id";
cboCustomer.DisplayMember = "Name";
cboCustomer.AutoCompleteMode = AutoCompleteMode.Suggest;
cboCustomer.AutoCompleteSource = AutoCompleteSource.ListItems;
cboCustomer.SelectedIndex = -1;





i需要来自ComboBoxStyle.DropDown名称的ID不是来自dropdowlist



i need id from name from ComboBoxStyle.DropDown not from dropdowlist

推荐答案

一旦你想使用ComboBoxStyle.DropDown,你想让你的用户编辑/输入下拉列表中已有的东西。所以有两种情况:





1.如果用户选择已经在下拉列表中的内容,那么你可以访问通过你的comboBox的SelectedValue属性选择ID。



2.否则,它应该是一个新项目,行为取决于你,例如,你可能想要显示一些消息框,要求用户添加新项目或自动添加新项目(使用新的自动生成的ID)。
Once you want to use ComboBoxStyle.DropDown, you want to allow your user to edit/type something other than ones already in the drop down list. So there are 2 cases:


1. If user chooses something which is already in the drop down list, then you can access the selected ID via SelectedValue property of your comboBox.

2. Otherwise, it should be a new item, the behavior is depending on you, for example, you may want to show some message box to ask for user to add new item or automatically add the new item (with a new automatically generated ID).


这篇关于如何获取组合框下拉列表自动完成选择的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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