如果用户不想在下拉列表中选择项目,如何允许用户在下拉列表中写入 [英] How to allow the user to write in the dropdown if he/she don't want to select the item in dropdown list

查看:71
本文介绍了如果用户不想在下拉列表中选择项目,如何允许用户在下拉列表中写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,我将提供用户将选择的城市列表。我还想为那些不属于我所提供的城市的人提供其他选项,并允许他们写出城市名称。我手动添加了一个带有文本others的listitem,但是当我从表中检索数据并填充下拉列表时,它会替换我手动添加的项目。怎么做?

解决方案

尝试以下代码和任何疑问,只需在此解决方案下面发表评论

  private   void  comboBox1_SelectedIndexChanged( object  sender ,EventArgs e)
{
if (comboBox1.Text == < span class =code-string> 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 ;
// 编写在城市表中插入项目的方法
DataInsert() ;
// 在combobox中加载项目的写入方法
DataLoad();

}
}







谢谢&问候,

Anand。 ģ


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?

解决方案

Try the following code and any doubt and need just comment below this solutions

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


这篇关于如果用户不想在下拉列表中选择项目,如何允许用户在下拉列表中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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