Winform DataPropertyName sur Datagridview d'une classe
Bonjour à tous,
Voilà mon souci, coté classes ça donne ça:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| // une de mes classes
public class Transport
{
public string Identifier { get; set; }
public string Type { get; set; }
public Instructions Instruction { get; set; }
public string Metadata { get; set; }
}
// une autre de mes classes
public class Instructions
{
public string Identifier { get; set; }
public string Label { get; set; }
public bool Enabled { get; set; }
} |
coté code de mon winform, j'ai créé
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| readonly BindingList<Transport> myTransports = new BindingList<Transport>();
// avec la création en manuelle de mes colonnes de dgv
DgvTransports.AutoGenerateColumns = false;
DgvTransports.Columns.Add(new DataGridViewCheckBoxColumn
{
DataPropertyName = "Select",
HeaderText = "",
Width = 20,
Resizable = DataGridViewTriState.False
});
DgvTransports.Columns.Add(new DataGridViewTextBoxColumn
{
DataPropertyName = "Identifier",
HeaderText = "Id",
ReadOnly = true
});
DgvTransports.Columns.Add(new DataGridViewTextBoxColumn
{
DataPropertyName = "Type",
HeaderText = "Type Transport"
Resizable = DataGridViewTriState.False
});
// Le binding
DgvTransports.DataSource = myTransports; |
Pour ajouter des lignes à mon dgv, je passe par:
Code:
myTransports.Add( new Transport(...);
Question: Comment je dois définir mes DataPropertyName de mes colonnes pour afficher par exemple la partie Instructions.Label de mon objet transport
DataPropertyName ="Transport.Instructions.Label"; ne fonctionne pas :(
Est-ce que je m'y prends mal ? Faut-il passer par un datatable, dataset ou autre chose ?
Merci d'avance pour votre aide sur ce problème de grand débutant :-/