我的 Windows 表单加载中有以下代码:
private void Panou_Load(object sender, EventArgs e)
{
List<string>[] list;
//list in a array with all elements from a select query
list = Conexiune.Select();
dataGridView1.Rows.Clear();
for (int i = 0; i < list[0].Count; i++)
{
int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = list[0][i];
dataGridView1.Rows[number].Cells[1].Value = list[1][i];
dataGridView1.Rows[number].Cells[2].Value = list[2][i];
dataGridView1.Rows[number].Cells[4].Value = list[4][i];
dataGridView1.Rows[number].Cells[5].Value = list[5][i];
dataGridView1.Rows[number].Cells[6].Value = list[6][i];
}
}
在我的 datagridview 上,第 4 个单元格是一个组合框。如何使用我的选择(list[3][i] 变量)中的值填充组合框?
更新 1:
private void Panou_Load(object sender, EventArgs e)
{
List<string>[] list;
list = Conexiune.Select();
dataGridView1.Rows.Clear();
for (int i = 0; i < list[0].Count; i++)
{
int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = list[0][i];
dataGridView1.Rows[number].Cells[1].Value = list[1][i];
dataGridView1.Rows[number].Cells[2].Value = list[2][i];
(dataGridView1.Columns[3] as DataGridViewComboBoxColumn).DataSource = new List<string> { list[3][i] };
dataGridView1.Rows[number].Cells[4].Value = list[4][i];
dataGridView1.Rows[number].Cells[5].Value = list[5][i];
dataGridView1.Rows[number].Cells[6].Value = list[6][i];
}
}
http://i.stack.imgur.com/0WLDr.jpg
更新 2:
private void Panou_Load(object sender, EventArgs e)
{
List<string>[] list;
list = Conexiune.Select();
dataGridView1.Rows.Clear();
(dataGridView1.Columns[3] as DataGridViewComboBoxColumn).DataSource = new List<string> { "", "activ", "inactiv", "neverificat" };
for (int i = 0; i < list[0].Count; i++)
{
int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = list[0][i];
dataGridView1.Rows[number].Cells[1].Value = list[1][i];
dataGridView1.Rows[number].Cells[2].Value = list[2][i];
dataGridView1.Rows[number].Cells[3].Value = list[3][i];
dataGridView1.Rows[number].Cells[4].Value = list[4][i];
dataGridView1.Rows[number].Cells[5].Value = list[5][i];
dataGridView1.Rows[number].Cells[6].Value = list[6][i];
}
}