Title: Adding class list to combobox
Tags: c#;list;class;combobox
Question: I'm making a list of groupnames which the user writes down in a textbox. After checking whether the groupname already exists, it adds it to the list.
I'm trying to add the objects to this list:
List<Group&gt; Groups = new List<Group&gt;();
The problem I'm having is that I keep getting the error:
An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
This happens due to the line of code that is supposed to add the groupnames in the combobox:
cbxGroups.DataSource = Groups.ToString();
This is what the class that the list is based on looks like:
class Group
//Fields
private string nameGroup;
//Properties
public string NameGroup
get { return this.nameGroup; }
set { nameGroup = NameGroup; }
//Constructor
public Groep(string name)
this.nameGroup = name;
I'm not sure how to solve this and I was hoping I could find some answers here.

Here is the accepted answer: You can use Linq Select method to get collection of group names.
cbxGroups.DataSource = Groups.Select(g =&gt; g.NaamGroep).ToList();
ToString() implementation of List returns it's type in string form, not items.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:12/30/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><list><class><combobox>', 'Title': 'Adding class list to combobox', 'ViewCount': 418, 'id': 34530913, 'user_AboutMe': None, 'user_AccountId': 7464530.0, 'user_DisplayName': 'AniBankai', 'user_Reputation': 43.0, 'user_Views': 9.0, 'user_id': 5674636.0}}