首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在文本框上显示建议

在文本框上显示建议
EN

Stack Overflow用户
提问于 2014-02-07 11:39:09
回答 1查看 2.9K关注 0票数 1

我正在制作销售发票,我正在自动填写有关领域的产品数据,比如当用户在产品代码文本框中输入产品代码时,产品名称和产品价格文本框通过从DB检索数据自动填写,我希望当用户在这里开始输入代码时,程序给出有关数据库中所有产品的建议。就像当用户输入1时,程序给出关于产品代码的建议,以1开头的产品代码显示自己,用户只选择他想要的代码。

我对“产品代码”文本框的文本更改事件所做的代码是

代码语言:javascript
复制
 private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (txtProductCode1.Text == "")
            {
                txtProductName1.Text = "";
                txtQty.Text = "";
                txtSalePrice.Text = "";
                txtTotal.Text = "";
            }
            string sql = "select productprice, ProductName";
            sql += "  from dbo.productlog";
            sql += " where productCode = '" + txtProductCode1.Text + "'"; // Placing ProductCode in single quotes because it's not an int column, but a varchar column, in SQL server


            SqlConnection cn = new SqlConnection();
            SqlCommand rs = new SqlCommand();
            SqlDataReader sdr = null;
            clsConnection clsCon = new clsConnection();

            clsCon.fnc_ConnectToDB(ref cn);

            rs.Connection = cn;
            rs.CommandText = sql;
            sdr = rs.ExecuteReader();

            if (sdr.Read())
            {

                txtProductName1.Text = sdr["ProductName"].ToString();
                txtSalePrice.Text = sdr["ProductPrice"].ToString();
            }

            else if (txtProductName.Text == "")
            {
                goto exitPoint;

            }

            else if (!sdr.Read())
            {
                MessageBox.Show("Data not found", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtProductName.Focus();
            }

        exitPoint:
            sdr.Close();
            rs = null;
            cn.Close();
        }

如何在文本框中显示有关产品代码的建议?

编辑:

它不是一个风车应用程序,意味着它是一个基于桌面的应用程序,我正在用C#.net使用VS2010创建它

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-07 11:52:49

看看这个,希望这对你有用。

http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.autocompletemode%28v=vs.110%29.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21626797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档