Skip to content

Instantly share code, notes, and snippets.

@bernardobrezende
Created November 24, 2011 17:35
Show Gist options
  • Save bernardobrezende/1391870 to your computer and use it in GitHub Desktop.
Save bernardobrezende/1391870 to your computer and use it in GitHub Desktop.
Exemplo de bind em um DataGridView - Windows Forms
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var clientes = new List<Cliente>()
{
new Cliente { Id = 0, Nome = "john doe I", Prop3 = "foo", Prop4 = "foo", Prop5 = "foo" },
new Cliente { Id = 1, Nome = "john doe II", Prop3 = "foo", Prop4 = "foo", Prop5 = "foo" },
new Cliente { Id = 2, Nome = "john doe III", Prop3 = "foo", Prop4 = "foo", Prop5 = "foo" },
};
this.dataGridView1.DataSource = clientes.OrderBy(y => y.Nome).Select(x => new { Id = x.Id, Nome = x.Nome }).ToList();
this.dataGridView1.Columns["Id"].Visible = false;
}
}
public class Cliente
{
public int Id { get; set; }
public string Nome { get; set;}
public string Prop3 { get; set; }
public string Prop4 { get; set; }
public string Prop5 { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment