私は3つの列、テキストボックス、コンボボックス、テキストボックスをこの順序で持っています:
this.columnLocalName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.columnLocalAddress = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.columnLocalPort = new System.Windows.Forms.DataGridViewTextBoxColumn();
そして、それらは次のように datagridview に表示されます。
this.dataGridViewLocalProfile.Columns.AddRange(
new System.Windows.Forms.DataGridViewColumn[] {
this.columnLocalName,
this.columnLocalAddress,
this.columnLocalPort});
後で、次のように各コンボボックス セルに異なる値を追加しようとします。
foreach (profile in localProfile.List)
{
DataGridViewComboBoxCell cell =(DataGridViewComboBoxCell)
(dataGridViewLocalProfile.Rows[dataGridViewLocalProfile.Rows.Count - 1].
Cells["columnLocalAddress"]);
cell.Items.Clear();
cell.Items.Add(profile.Address.ToString());
dataGridViewLocalProfile.Rows.Add(
new string[] { profile.Name, profile.Address, profile.Port });
}
これにより、最初の列と最後の列が入力され、コンボボックス列が空のデータグリッドが生成されます。私が扱うデータエラーで。メッセージは次のとおりです。
DataGridViewComboBoxCell value is not valid.
ほとんどの投稿を読みましたが、これに対する解決策が見つかりません。
次のようにデータソースを設定してみました:
cell.DataSource = new string[] { profile.Address };
dataerror と言ってまだ空のコンボボックス列を取得しています
DataGridViewComboBoxCell value is not valid.
各コンボボックスセルに異なる値を追加するので、これは非常に難しいと思います。
誰でも、どうすればこれを機能させることができるか教えてください。
/一番