c# - How to map properties of inner/nested classes in DataGridView through BindingSource? -


i have separate project data layer , there 2 basic classes there:

[serializable] public class nesinfo {     public string filename { get; private set; }     public string directory { get; private set; }     public mapperinfo mapperinfo { get; set; } } 

and

[serializable] public class mapperinfo {     public string number { get; set; }     public string prop1{ get; set; }     public string prop2 { get; set; } } 

now want datagridview display columns this:
[filename][directory][number][prop1][prop2]

how can achieve using bindingsource?

i've tried using bindingsource in datagridview, instead of 5 columns, 3 (the nested class treated 1 column, inner properties should there instead):

enter image description here

and cannot select inner properties of mapperinfo class when trying add columns: enter image description here

you can create new class properties want display in grid , map existing class either manually or using third-party libraries (ex. automapper). bind new class grid.

public class mygridclass {     public string filename { get; set; }     public string directory { get; set; }     public string number { get; set; }     public string prop1 { get; set; }     public string prop2 { get; set; } }  nesinfo ni = ...  mygridclass gc = new mygridclass ( ); gc.filename = ni.filename; gc.directory = ni.directory; gc.number = ni.mapperinfo.number; gc.prop1 = ni.mapperinfo.prop1; gc.prop2 = ni.mapperinfo.prop2; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -