1時間くらい行き詰ったので掲載 ソースの張り方が汚いですが、これは後で修正します。
//通常のテキスト形式の表を作成 DataSet ds = new DataSet(); DataTable dt = ds.Tables.Add("Computer"); DataRow dr; dt.Columns.Add("メーカー"); dt.Columns.Add("パソコン名"); dr = dt.NewRow(); dr["メーカー"] = "NEC"; dr["パソコン名"] = "ValueStar"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["メーカー"] = "SONY"; dr["パソコン名"] = "VAIO"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["メーカー"] = "DELL"; dr["パソコン名"] = "Precision"; dt.Rows.Add(dr); dataGridView1.DataSource = ds; dataGridView1.DataMember = "Computer"; //指定セルにデータコンボボックスを作成 dataGridView1[1, 1] = new DataGridViewComboBoxCell(); //既に入っているテキストデータがエラーの原因となるため初期化 dataGridView1[1, 1].Value = null; //データコンボボックスのリストの内容を追加 ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items.Add("あああ"); ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items.Add("いいい"); ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items.Add("ううう"); ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items.Add("えええ"); ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items.Add("おおお"); //データコンボボックスの初期値を設定 dataGridView1[1, 1].Value = ((DataGridViewComboBoxCell)dataGridView1[1, 1]).Items[2];
0 件のコメント:
コメントを投稿