Reputation: 34198
I'm filling a ComboBox with DataGridView cells' values. Now, I don't want to repeat values which already are in the ComboBox.
So, there is for example:
I want to remove all values which appear more than once.
This is my code:
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;
}
Sorry for my bad English.
Upvotes: 1
Views: 353
Reputation: 9784
Seems like you want a unique list for the dataSource
for your ComboBox. If you are using .NET 3 and above you can use:
List<T> withDupes = SellerNameList;
List<T> noDupes = withDupes.Distinct().ToList();
comboBox1.DataSource = noDupes;
Upvotes: 5
Reputation: 3009
The easiest way to do this would be via a collection and LINQ , i would say.
Try this link for an introduction
Upvotes: 2