-4

I'am struggling with the following, I have a datatable with some columns what i want is to have the items in this column displayed in a combobox. But it must not display double items.

How can i do this?

PandaNL
  • 828
  • 5
  • 18
  • 40

2 Answers2

1

Try this:

private void FillComboFromColumnIndex(int columnIndex){
  yourDataTable.AsEnumerable()
               .Select(r=>r[columnIndex])
               .Where(x=>x != null)
               .Distinct().ToList()
               .ForEach(x=>yourComboBox.Items.Add(x));
}
//To add all the items in column at index 1, do this
FillComboFromColumnIndex(1);
King King
  • 61,710
  • 16
  • 105
  • 130
0

Try this, I'm not sure is it right answer on your question because I'm not sure if I have understood you as well: Hidden Id With ComboBox Items?

Community
  • 1
  • 1
Zoran Marjanovic
  • 355
  • 2
  • 3
  • 12