private void AddBoxInDataGrid()
2 {
3 Company com = new Company();
4 DataSet ds = new DataSet();
5 ds = com.GetListAll();
6 this.dgCompany.DataSource = ds.Tables["ds"];
7
8 if(!this.dgCompany.TableStyles.Contains("ds"))
9 {
10 DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
11 dgdtblStyle.MappingName = ds.Tables[0].TableName;
12 this.dgCompany.TableStyles.Add(dgdtblStyle);
13 }
14 DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)this.dgCompany.TableStyles[0].GridColumnStyles[8];
15 ComboBox cb = new ComboBox();
16 //combobox绑定数据库中CompanyType表
17 DataSet ds1 = new DataSet();
18 CompanyType ct = new CompanyType();
19 ds1 = ct.GetList();
20 cb.ValueMember = "ID";
21 cb.DisplayMember = "Name";
22 cb.DataSource = ds1.Tables[0].DefaultView;
23
24 cb.Cursor = Cursors.Arrow;
25 cb.DropDownStyle= ComboBoxStyle.DropDownList;
26 cb.Dock = DockStyle.Fill;
27 cb.SelectionChangeCommitted +=new EventHandler(cb_SelectionChangeCommitted);
28 dgtb.TextBox.Controls.Add(cb);
29 }
30 private void cb_SelectionChangeCommitted(object sender, EventArgs e)
31 {
32 this.dgCompany[this.dgCompany.CurrentCell] = ((ComboBox)sender).Text;
33 index = ((ComboBox)sender).SelectedValue.ToString();
34 }
2 {
3 Company com = new Company();
4 DataSet ds = new DataSet();
5 ds = com.GetListAll();
6 this.dgCompany.DataSource = ds.Tables["ds"];
7
8 if(!this.dgCompany.TableStyles.Contains("ds"))
9 {
10 DataGridTableStyle dgdtblStyle = new DataGridTableStyle();
11 dgdtblStyle.MappingName = ds.Tables[0].TableName;
12 this.dgCompany.TableStyles.Add(dgdtblStyle);
13 }
14 DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)this.dgCompany.TableStyles[0].GridColumnStyles[8];
15 ComboBox cb = new ComboBox();
16 //combobox绑定数据库中CompanyType表
17 DataSet ds1 = new DataSet();
18 CompanyType ct = new CompanyType();
19 ds1 = ct.GetList();
20 cb.ValueMember = "ID";
21 cb.DisplayMember = "Name";
22 cb.DataSource = ds1.Tables[0].DefaultView;
23
24 cb.Cursor = Cursors.Arrow;
25 cb.DropDownStyle= ComboBoxStyle.DropDownList;
26 cb.Dock = DockStyle.Fill;
27 cb.SelectionChangeCommitted +=new EventHandler(cb_SelectionChangeCommitted);
28 dgtb.TextBox.Controls.Add(cb);
29 }
30 private void cb_SelectionChangeCommitted(object sender, EventArgs e)
31 {
32 this.dgCompany[this.dgCompany.CurrentCell] = ((ComboBox)sender).Text;
33 index = ((ComboBox)sender).SelectedValue.ToString();
34 }