Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Master
- {
- public string MasterName = "Something";
- public List<Detail> details = new List<Detail>();
- }
- public class Detail
- {
- public string Foo = "Test";
- }
- DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
- column.DataPropertyName = "Details.Foo";
- column.HeaderText = "Foo header";
- dgv.Columns.Add(column);
- public class FormulariosENT {
- #region PROPERTIES
- public int IdFromulario { get; set; }
- public string DescripcionFormulario { get; set; }
- #endregion
- #region PUBLIC METHODS
- public override string ToString() {
- return DescripcionFormulario;
- }
- List<Detail> list = new List<Detail>();
- for (int i = 0; i < 10; i++)
- {
- Detail d = new Detail();
- d.Foo = "test";
- list.Add(d);
- }
- this.dgv.DataSource = list;
- this.dgv.Columns[0].Visible = false;
- DataGridViewTextBoxColumn dgvc = new DataGridViewTextBoxColumn();
- dgvc.HeaderText = "列标题";
- dgvc.DataPropertyName = "foo";
- this.dgv.Columns.Add(dgvc);
- public class Detail
- {
- private string foo;
- public string Foo
- {
- get { return foo; }
- set { foo = value; }
- }
- }
- class MyClass
- {
- public int Id;
- public MyOtherClass OtherClass;
- }
- class MyOtherClass
- {
- public string Name;
- public int Number;
- }
- private void dgv_CellFormatting( object sender, DataGridViewCellFormattingEventArgs e )
- {
- MyClass data = dgv.Rows[ e.RowIndex ].DataBoundItem as MyClass;
- dgv.Rows[ e.RowIndex ].Cells[ "colName" ].Value = data.OtherClass.Name;
- dgv.Rows[ e.RowIndex ].Cells[ "colNumber" ].Value = data.OtherClass.Number;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement