2017-01-14 5 views
1

C#datagridviewに関する助けが必要です。 データソースからdatagridviewを生成したいと思います。 データグリッドビューには4列があります。 カラム1:ファーストネーム カラム2:姓 カラム3:性別 カラム4:国。 国の列はコンボボックスの列です。データソースのDatagridviewにコンボボックスの列を挿入する

これに応じてデータソースを作成し、データソースをグリッドに設定しました。 最初の3つの列が生成されていますが、コンボボックスが追加されていません。 は、ここで私はアプリを実行すると、データグリッドが3列に現れているが、コンボボックスの列が生成されていない

List<Mydataclass> dataclassList = new List<Mydataclass>(); 
for (int i = 0; i < 5; i++) 
     { 
      Mydataclass dataclass = new Mydataclass(); 
      dataclass.firstname = "firstname" + i; 
      dataclass.secondname = "second name" + i; 
      dataclass.gender = "gender" + i; 
      dataclass.country = new string[] { "BD", "AUS"}; 

      dataclassList.Add(dataclass); 

     } 
BindingSource bindingSource1 = new BindingSource(); 

     bindingSource1.DataSource = dataclassList; 
     dataGridView1.DataSource = bindingSource1; 

私のアプリのコード例です。

問題を見つけてください。

ありがとうございます。

答えて

1

これは私のためにどのような作品です:

// This is the list of items to be displayed in the DataGridView Combobox Column 
string[] listOfItems = new string[]{"Apple", "Banana", "Orange"}; 

// Define a BindingSource and add the items to it (alas, there is no AddRange()) 
BindingSource bs = new BindingSource(); 

foreach (string item in listOfItems) 
{ 
    bs.Add(item); 
} 

// Set binding (MyComboColumn is the name you gave to your combo column, see image below) 
this.MyComboColumn.DataSource = bs; 

enter image description here

関連する問題