Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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 :
C#
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 need id from name from ComboBoxStyle.DropDown not from dropdowlist
Posted
Updated 30-Apr-13 0:33am
v4
Comments
CHill60 26-Apr-13 11:41am    
When do you want to get the information - as the selection is changed or at some other time?

1 solution

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).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900