简体   繁体   English

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

[英]how to automatically set value of textbox according to value of another textbox

I had textbox1 , textbox2 , and textbox3 I want to automatically set value of textbox2 and textbox3 according to value of textbox1 which has an auto complete method as below... 我有textbox1textbox2 ,并textbox3我要自动设置的值textbox2textbox3根据价值textbox1具有如下的自动完成的方法...

what should I do within the while clause to automatically set value of textbox2 and textbox3 after finishing auto complete at textbox1 ?? 在textbox1完成自动完成后,在while子句中如何自动设置textbox2textbox3值?

I am working on these error form two days everything is public within my code... I have one think i am wondering about is that new class should be defined within the namespace scope like namespace { Class class_name} but I am defining the class instead of another class like name spaces {class Class_name1 {classs Class_name2 } } but my problem is that when i put my class within the name spaces scope I am getting alot of error and it wont recognize a lot of key words ... so please would tha be the problem ?? 我正在处理这些错误表格,两天后代码中的所有内容都是公开的...我想我想知道是应该在名称空间范围内定义新类,例如namespace { Class class_name}但是我正在定义该类我的另一个问题是像name spaces {class Class_name1 {classs Class_name2 } }但是我的问题是,当我将我的类放在名称空间范围内时,会出现很多错误,并且它无法识别很多关键字...所以请这可能是个问题吗? and if yes please can you lead me to solve this ??? 如果是的话,您能带我解决这个问题吗?

public class PopulateProduct { public string ProductDesc { get; 公共类PopulateProduct {公共字符串ProductDesc {get; set; 组; } public decimal UnitPrice { get; }公开的十进制单价{get; set; 组; } } }}

    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..." “ ...我的代码中所有内容都是公开的...”

Please check again. 请再次检查。 Properties of your Object model is not public yet (and Object is not a good name for your model ... how about Product ?) : 您的Object模型的属性尚未公开(并且Object不是该模型的好名字... Product怎么样?):

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

Regarding the last part of the error message, that's because DataReader["column_name"] returns object. 关于错误消息的最后一部分,这是因为DataReader["column_name"]返回对象。 You need to explicitly cast the result to suitable type : 您需要将结果显式转换为合适的类型:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM