简体   繁体   English

ComboBox 的 SelectedIndexChanged 事件 - 填充控件值

[英]SelectedIndexChanged event of ComboBox - populate control values

When ComboBox SelectedIndexChanged event occurs, I need to populate the respective controls with its values.当 ComboBox SelectedIndexChanged事件发生时,我需要用其值填充相应的控件。 I am using entity framework 6 for the approach.我正在使用实体框架 6 作为方法。 I am using c# windows forms and .net framework 4.5.我正在使用 c# windows 窗体和 .net 框架 4.5。 My code is :我的代码是:

private void comboBoxCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
    using (ReliableTradersEntities entities = new ReliableTradersEntities())
    {
        m_blouse = new BLOUSE_MEASUREMENT();
        m_pardi = new PARDI_MEASUREMENT();
        m_lengha = new LHENGA_MEASUREMENT();

        var res = from c in entities.CUSTOMERs
                        join p in entities.PARDI_MEASUREMENT on c.CUSTOMERID equals p.CUSTOMERID
                        join l in entities.LHENGA_MEASUREMENT on c.CUSTOMERID equals l.CUSTOMERID
                        join b in entities.BLOUSE_MEASUREMENT on c.CUSTOMERID equals b.CUSTOMERID
                        select new 
                        {

                            p.PARDILENGTH,
                            p.PARDILIMIT,
                            p.SHOULDER,
                            p.SHOULDERTOHEAD,
                            p.HEADTOBACK,
                            p.HALFHEADROUND,
                            p.NIQABLENGTH,
                            p.KAS,
                            l.LHENGALENGTH,
                            l.LHENGALIMIT,
                            l.BELTOPTION,
                            l.ISPOCKET,
                            l.ISZIP,
                            l.STYLE,
                            l.STYLESIZE,
                            l.ALINE,
                            b.BLOUSELENGTH,
                            b.CHEST,
                            b.WAIST,
                            b.SLEEVES,
                            b.NECK,
                            b.POINT,
                            b.BLOUSEOPENING
                        };
        textBoxPL.Text = m_pardi.PARDILENGTH;
    }

}

You have created an anonymous type that is returned in the variable res with all the info extracted by your query.您已经创建了一个匿名类型,该类型在变量res 中返回,其中包含您的查询提取的所有信息。 You have not filled the initial three class instances.您还没有填充最初的三个类实例。

You need to initialize your instances using the res variable with您需要使用res变量初始化您的实例

// The query returns an IEnumerable, you need to extract the first element
var x = res.FirstOrDefault();
if(x != null)
{
    m_pardi = new PARDI_MEASUREMENT();
    m_pardi.PARDILENGTH = x.PARDILENGTH;
    .... 
}

But you could use directly the res variable但是你可以直接使用res变量

 var x = res.FirstOrDefault();
 if(x != null)
 {
     textBoxPL.Text = x.PARDILENGTH;
     .... and so on....
 }

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

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