Created
November 24, 2011 17:35
-
-
Save bernardobrezende/1391870 to your computer and use it in GitHub Desktop.
Exemplo de bind em um DataGridView - Windows Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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