Hi,
I'm new to programming and I'm stuck.
I want to show the name and surename of the generated duos in a datagrid.
No matter what I try: the columnheaders are created, but the names do not show.
Help is much appreciated.
I'm new to programming and I'm stuck.
I want to show the name and surename of the generated duos in a datagrid.
No matter what I try: the columnheaders are created, but the names do not show.
Help is much appreciated.
C#:
private void btnCalculate_Click(object sender, EventArgs e)
{
List<Person> people = new List<Person>()
{
new Person { Name = "A", Surname = "F", Id = 1},
new Person { Name = "B", Surname = "G", Id = 2},
new Person { Name = "C", Surname = "H", Id = 3},
new Person { Name = "D", Surname = "I", Id = 4},
new Person { Name = "E", Surname = "J", Id = 5},
};
List<Duo> duos = new List<Duo>();
for (int i = 0; i < people.Count; i++)
{
Duo duo = new Duo();
duo.Person1 = people[i];
if (i + 1 < people.Count)
duo.Person2 = people[i + 1];
duos.Add(duo);
}
//dataGridDuo.DataSource = people;
dataGridDuo.AutoGenerateColumns = false;
DataGridViewTextBoxColumn person1NameColumn = new DataGridViewTextBoxColumn();
person1NameColumn.HeaderText = "Person1 Name";
person1NameColumn.DataPropertyName = "Person1.Name";
DataGridViewTextBoxColumn person1SurenameColumn = new DataGridViewTextBoxColumn();
person1SurenameColumn.HeaderText = "Person1 Surename";
person1SurenameColumn.DataPropertyName = "Person1.Surname";
DataGridViewTextBoxColumn person2NameColumn = new DataGridViewTextBoxColumn();
person2NameColumn.HeaderText = "Person2 Name";
person2NameColumn.DataPropertyName = "Person2.Surname";
DataGridViewTextBoxColumn person2SurnameColumn = new DataGridViewTextBoxColumn();
person2SurnameColumn.HeaderText = "Person2 Surname";
person2SurnameColumn.DataPropertyName = "Person2.Surname";
dataGridDuo.Columns.Add(person1NameColumn);
dataGridDuo.Columns.Add(person1SurenameColumn);
dataGridDuo.Columns.Add(person2NameColumn);
dataGridDuo.Columns.Add(person2SurnameColumn);
dataGridDuo.DataSource = duos;
}