如何根据另一个文本框的值自动设置文本框的值

how to automatically set value of textbox according to value of another textbox

我有 textbox1textbox2textbox3 我想根据 [=11] 的值自动设置 textbox2textbox3 的值=] 具有如下所示的自动完成方法...

我应该在 while 子句中做什么才能在 textbox1 完成自动完成后自动设置 textbox2textbox3 的值??

我正在处理这些错误表格两天,所有内容都在我的代码中 public...我想我想知道的是新的 class 应该在命名空间范围内定义像 namespace { Class class_name} 但我正在定义 class 而不是另一个 class 像 name spaces {class Class_name1 {classs Class_name2 } } 但我的问题是当我把我的 class 放在名称空间范围内时我我遇到了很多错误,它无法识别很多关键词……所以请问这是问题所在吗??如果是的话请你带我解决这个问题???

public class 填充产品 { public 字符串 ProductDesc { 得到;放; } public十进制单价{get;放; } }

    Dictionary<string, PopulateProduct> dict = new Dictionary<string, PopulateProduct>();

    public void load()
    {
        string connstr = "user id=rawpic;password=admin";
        string cmdtxt = @"select PRODUCT_ID,DESCRIPTION,UNIT_PRICE 
                              from products";

        AutoCompleteStringCollection autocom = new AutoCompleteStringCollection();
        TB_PRODUCT_ID.AutoCompleteMode = AutoCompleteMode.Suggest;
        TB_PRODUCT_ID.AutoCompleteSource = AutoCompleteSource.CustomSource;
        TB_PRODUCT_ID.AutoCompleteCustomSource = autocom;

        using (OracleConnection conn = new OracleConnection(connstr))
        using (OracleCommand cmd = new OracleCommand(cmdtxt, conn))
        {
            try
            {
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    dict.Add((string)dr["PRODUCT_ID"],
                        new PopulateProduct()
                        {
                            ProductDesc = (string)dr["DESCRIPTION"],
                            UnitPrice = (decimal)dr["UNIT_PRICE"]
                        });
                    autocom.Add(dr["PRODUCT_ID"].ToString());
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }
    }


    private void TB_PRODUCT_ID_TextChanged(object sender, EventArgs e)
    {
        if (dict.ContainsKey(TB_PRODUCT_ID.Text)) 
        {
            TB_PRODUCTS_DESC.Text = dict[TB_PRODUCT_ID.Text].ProductDesc;
            TB_UNIT_PRICE.Text = dict[TB_PRODUCT_ID.Text].UnitPrice.ToString();
        }
    }

"...everything is public within my code..."

请再次检查。您的 Object 模型的属性还不是 public(并且 Object 不是您模型的好名称...... Product 怎么样?):

public class Product
{
    public string ProductDesc { get; set; }
    public decimal UnitPrice { get; set; }
}

关于错误消息的最后一部分,那是因为 DataReader["column_name"] returns 对象。您需要将结果显式转换为合适的类型:

dict.Add((string)dr["PRODUCT_ID"], 
         new Product() 
         { 
            ProductDesc = (string)dr["DESCRIPTION"], 
            UnitPrice = (decimal)dr["UNIT_PRICE"]
         });