/// <summary>
/// 给dataGridView绑定 ComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewComboBoxCell DgvCell = this.dataGridView1.Rows[e.RowIndex].Cells["Unit"] as DataGridViewComboBoxCell;//获得加入ComboBox的列
DataTable dt_com = new DataTable();
dt_com.Columns.Add("Unit", Type.GetType("System.String"));
DataRow dr = dt_com.NewRow();
dr["Unit"] = "个";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "台";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "套";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "包";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "箱";
dt_com.Rows.Add(dr);
DgvCell.DataSource = dt_com;
DgvCell.DisplayMember = "Unit";
DgvCell.ValueMember = "Unit";
}
/// 给dataGridView绑定 ComboBox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewComboBoxCell DgvCell = this.dataGridView1.Rows[e.RowIndex].Cells["Unit"] as DataGridViewComboBoxCell;//获得加入ComboBox的列
DataTable dt_com = new DataTable();
dt_com.Columns.Add("Unit", Type.GetType("System.String"));
DataRow dr = dt_com.NewRow();
dr["Unit"] = "个";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "台";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "套";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "包";
dt_com.Rows.Add(dr);
dr = dt_com.NewRow();
dr["Unit"] = "箱";
dt_com.Rows.Add(dr);
DgvCell.DataSource = dt_com;
DgvCell.DisplayMember = "Unit";
DgvCell.ValueMember = "Unit";
}