2010-11-21 128 views
1

我正在用DataGridView單元格的值填充ComboBox。現在,我不想重複已經存在於ComboBox中的值。DataGridView和ComboBox問題

因此,有例如:

  • 比爾·蓋茨
  • Steave喬布斯
  • Steave鮑爾默
  • Steave喬布斯

我想刪除這似乎超過所有值一旦。

這是我的代碼:

private void btnFilter_Click(object sender, EventArgs e) 
{ 
    ArrayList SellerNameList = new ArrayList(); 

    for (int i = 0; i < dataGridView1.Rows.Count; i++) 
    { 
     SellerNameList.Add(dataGridView1.Rows[i].Cells["cSellerName"].Value); 
    } 
    comboBox1.DataSource = SellerNameList; 
} 

對不起,我的英語不好。

回答

5

好像要用於dataSource您的組合框的唯一列表。如果您使用的是.NET 3及更高版本,則可以使用:

List<T> withDupes = SellerNameList; 
List<T> noDupes = withDupes.Distinct().ToList(); 

comboBox1.DataSource = noDupes;