Alex Freeman

Alex Freeman

  • NA
  • 1
  • 2.6k

Add a custom class object to a datagridview cell in winforms

Jul 19 2015 2:10 PM
I am trying to add a custom class object e.g. "employee" to a datagridview cell.  (Data Binding?)
 
Employee contains: int ID, string FirstName, string LastName.  In the class, I use the public override string ToString() to display "FirstName LastName".  
 
When I add the employee object to a DataGridViewTextBox cell, the employee FirstName LastName appears as predicted.  
 
I am under the impression that because I was using a textbox cell only the tostring() value of my object is being stored as the value and not the entire object.  I have added classes to comboboxes before and was able to bind to them when a specific object is selected and extract the ID to use.
 
Is there a way of creating a custom datagridview column that could store my entire class as a value to bind to it when clicked on?  I am new to .NET and C#.