Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one dropdown in wihch i am giving list of cities that user will select. I want to give others option also for those who don't belong to cities i have provided and allow them to write the cityname. I have added manually one listitem with the text "others" but when i retrive data from the table and fill the dropdown, it replaces the item i have added manually. How to do this?
Posted
Comments
Krunal Rohit 8-Mar-14 10:33am    
Can you make it bit clear ?

-KR
BillWoodruff 8-Mar-14 10:53am    
Obviously, you are going to have to update the Table to save the added names.

1 solution

Try the following code and any doubt and need just comment below this solutions
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Others")
                textBox1.Visible = true;
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                comboBox1.Items.Add(textBox1.Text);
                textBox1.Visible = false;
//write a method for inserting item in cities table
DataInsert();
// write method for loading items in combobox
DataLoad();

            }
        }



Thanks & Regards,
Anand. G
 
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