DataGridView DataBind an Array of Arbitrary Objects


/ Published in: C#
Save to your folder(s)

Stupidly simple -- just one pitfall: class to be bound must have Get/Set methods for reflection to discover. Which is annoying when it comes to client side classes auto generated from WSDL.


Copy this code and paste it in your HTML
  1. Foo[] foos = new Foo[2];
  2. DataGridView1.DataSource = foos;
  3.  
  4.  
  5. //This works.
  6. public class FooGood
  7. {
  8. public string Bar { get; set; }
  9. public string Baz { get; set; }
  10. }
  11. //This Doesn't
  12. public class FooBad
  13. {
  14. public string Bar;
  15. public string Baz;
  16. }

Report this snippet


Comments


You need to login to view comments.