怎样对datagridview里面的combox灵活添加参数???
近日,在做项目时,有一个这样的需求,在datagridview表格里面有一列类型是combox下拉框,需要在下拉框里面选择所要的参数,这些参数需要从配置文件里面读取出来,然后再添加到combox下拉框里面,这个功能自己也是查了好多的资料,方法如下,希望对大家有所帮助:
private void DetailOrderInfo_Load(object sender, EventArgs e)
{
//将卷格式填充在表格里面
dataGridView1.Rows[0].Cells["Column1"].Value = coilFormt + "-1";
//加载出口管芯规格参数
DataGridViewComboBoxCell dvgComBox = dataGridView1.Rows[0].Cells["Column4"] as DataGridViewComboBoxCell;
for (int i = 0; i < listParam.Count; i++)
{
dvgComBox.Items.Add(listParam[i]); //listParam是参数列表,这个参数是从配置文件里面读取出来的,然后放在了listParam里面
}
}
/// <summary>
/// 根据成品卷数量在datagridview上面显示行数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void combCount_SelectedIndexChanged(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
int count = int.Parse(combCount.Text);
for (int i = 0; i < count; i++)
{
dataGridView1.Rows.Add();
//加载卷号
dataGridView1.Rows[i].Cells[0].Value = coilFormt + "-" + (i + 1).ToString();
DataGridViewComboBoxCell dvgComBox = dataGridView1.Rows[i].Cells["Column4"] as DataGridViewComboBoxCell;
for (int j = 0; j < listParam.Count; j++)
{
dvgComBox.Items.Add(listParam[j]);
}
}
return;
}
主要的代码是
DataGridViewComboBoxCell dvgComBox = dataGridView1.Rows[0].Cells["Column4"] as DataGridViewComboBoxCell;
for (int i = 0; i < count; i++)
{
dvgComBox.Items.Add(param[i]);
}