| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 451 人关注过本帖
标题:ComboBox 数据绑定调试时的问题
只看楼主 加入收藏
niaomingjian
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-8-9
收藏
 问题点数:0 回复次数:2 
ComboBox 数据绑定调试时的问题
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            departmentComboBox.DataSource = LoadDepartmentData();    //该句执行完为什么跳转到departmentComboBox_SelectedIndexChanged()????????
            departmentComboBox.ValueMember = "DepartmentID";
            departmentComboBox.DisplayMember = "Name";
        }

        private DataView LoadDepartmentData()
        {
            string sqlConnectionString = @"Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=AdventureWorks;";
            string sqlSelect = "select DepartmentID,Name from HumanResources.Department";
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectionString);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt.DefaultView;
        }

        private void departmentComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            string message = "Selected:[" + departmentComboBox.SelectedValue + "]" + ((DataRowView)departmentComboBox.Items[departmentComboBox.SelectedIndex])["Name"];
            MessageBox.Show(message);
        }
    }
搜索更多相关主题的帖子: class 数据 private public 
2012-02-25 11:36
hudun1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-2-14
收藏
得分:0 
载入数据源啊
2012-02-25 13:16
niaomingjian
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-8-9
收藏
得分:0 
纠结了!自己想错了,本来就应该会执行departmentComboBox_SelectedIndexChanged(object sender, EventArgs e)的,这应该是进行了数据绑定的设置所触发的。本来还想为什么在调试的时候出现了突然的跳转,却找不到跳转的理由。花了好几个小时,不过失败中得经验嘛
2012-02-25 15:10
快速回复:ComboBox 数据绑定调试时的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012757 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved