I have a DataGridView control and I want to populate it with data.
I am using the DataSource property
// dgvDealAsset is DataGridView private void DealAssetListControl_Load(object sender, EventArgs e) { dgvDealAssets.AutoGenerateColumns = false; dgvDealAssets.DataSource = DealAssetList.Instance.Values.ToList(); }
Now problem number one. The class in my collection does not contain only simple types that I can map to columns using DataPropertyName. This is the class that is contained in the collection.
class MyClass { public String Name; MyOtherClass otherclass; } class MyOtherClass { public String Name; }
Now I bind MyClass properties to columns
col1.DataPropertyName = "Name" // Ok col2.DataPropertyName = "otherclass" // Not OK - I will have empty cell
The problem is that I want to display the otherclass.Name field. But if I try to write
col2.DataPropertyName = "otherclass.Name"
I get an empty cell.
I tried to manually set the column
private void DealAssetListControl_Load(object sender, EventArgs e) { dgvDealAssets.AutoGenerateColumns = false; dgvDealAssets.DataSource = DealAssetList.Instance.Values.ToList();
But this foreach loop takes about a minute to complete (2k items). How to solve this problem?
winforms datasource datagridview
Captain comic
source share