基本控件的用法

 

/*********************************comboBox的使用************************************************/
            this.comboBox1.Text = "aa";//为comboBox1赋值,显示在首项
            this.comboBox1.DataSource = "数据源(例如,datatable,泛型集合)";//绑定数据源
            this.comboBox1.DisplayMember = "字段";//显示的列
            this.comboBox1.ValueMember = "字段";//给程序员用,一般绑定的都是主键

 

 

 /************************dataGridView的使用(用于显示数据库的表)****************************************************/
           this.dataGridView1.DataSource = DBHelp.GetTable();//绑定的是表,或类(切记类必须全部属性是同一个类的,如果是属性类,那么那个属性无法显示另一个类的数据)

    //获取当前选中的行的单元格的数据(单元格的索引是从0开始)
            string a= this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            //获取指定行的单元格的数据
            string n= this.dataGridView1.Rows[0].Cells[0].Value.ToString();

posted @ 2014-06-26 00:41  单方面  阅读(181)  评论(0编辑  收藏  举报