Skip to content

A quick utility class for converting IEnumerables into easily bindable DataTables

Notifications You must be signed in to change notification settings

brushfiretech/datatableproxy

 
 

Repository files navigation

DataTableProxy

A quick utility class for converting IEnumerables into easily bindable DataTables. Available as a NuGet Package.

This version has been ported forward to netstandard 2.0

Usage:

var dtp = new DataTableProxy<YourObject>();
dtp.ColumnDefs.Add("ID", yo => yo.Id);
dtp.ColumnDefs.Add("Name", yo => yo.Name);
dtp.ColumnDefs.Add("Last Date", yo => yo.Dates.Max());

dtp.DataSource = YourObjectRepository.GetAll();

dtp.FillTable();

dataGridView1.DataSource = dtp.Table;

Or use the new Fluent Syntax:

dataGridView1.DataSource = YourObjectRepository.GetAll().ToTable(
   new ClassMapping<YourObject>()
       .AddColumn("ID", yo => yo.Id)
       .AddColumn("Name", yo => yo.Name)
       .AddColumn("Last Date", yo => yo.Dates.Max())
    );

Or use the built in reflection to automatically set up the columns:

dataGridView1.DataSource = YourObjectRepository.GetAll().ToTable(
    new ClassMapping<YourObject>().AddAllPropertiesAsColumns()
    );

Notes: DataTableProxy will intelligently discover the datatype for each column added based on the return type of the first non-null evaluation. DataTableProxy will call "ToString" on reference-type return values.

Licence Information

Copyright (c) 2012 Tom Dietrich. All rights reserved.

Redistribution and use in source and binary forms are permitted.

THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

About

A quick utility class for converting IEnumerables into easily bindable DataTables

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%