I'm trying to populate a datagridview on a form with a list of objects with multiple properties in order to create a table.
private void display()
{
DataGridViewName.AutoGenerateColumns = false;
DataGridViewName.DataSource = Class.List;
DataGridViewName.ClearSelection();
}
When I have AutoGenerateColumns set to false, nothing shows up in the cells (I used designmode to input column headers), if I change AutoGenerateColumns to true, it adds a column for each parameter and the column header shows the name of the property. Any explanation why the data isn't showing with it set to false, and if not then is there a way to change the column header name from the property name to something else on the autogenerated columns?
DataPropertyName
match one of the class properties names? – JohnGDataGridView
go Boom. It is better to set it by code in constructor:yourColumn1.DataPropertyName = nameof(YourClass.YourProperty);
– vasily.sib