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];
}
}
私のデータグリッドビューでは、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];
}
}