C#返回ComboBox对象 [英] C# Returning a ComboBox Object

查看:171
本文介绍了C#返回ComboBox对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..在业务层中,我有一个返回comboBox的方法.

Hi.. In the business Layer I have a method that returns a comboBox.

public ComboBox GetTrainingTypes()
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                ComboBox combo = new ComboBox();

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT TrainingType FROM TrainingProgram";

                SqlDataReader reader;
                  
                conn.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    combo.Items.Add(reader[0].ToString());
                }
                return combo;
            }
        }


好的,然后我有一个WPF comboBox,我想要在返回的组合框中显示项目.请帮助将表示层组合框分配给对象:)

名称:cmbTraining


谢谢


ok and Then i have a WPF comboBox that i want to have the Items in the returned Combo box. Please help to assign the presentation layer combo box to the object :)

name: cmbTraining


Thank you

推荐答案

如果您有在业务层中返回ComboBox的方法,则您没有业务层.业务层可以使用其语义形式的数据,但不能直接使用UI.您的ComboBox应该仅在表示层上.您所有的问题是因为您想弄乱图层.把它们整理好;您的问题就会消失.

—SA
If you have a method that returns a ComboBox in a Business Layer, you don''t have a Business Layer. A Business Layer can work with data in its semantic form, but never directly with UI. Your ComboBox should be on Presentation Layer only. All your problem is because you''re trying to mess up layers. Put them in order; and your problem will disappear.

—SA


返回数组而不是组合框


这篇关于C#返回ComboBox对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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