C#C
C#2y ago
2 replies
TJacken

WinForms DataGridView complex binding

Is this possible to bind on datagrid view?

I have this class Relation, which is objects are populated in dropdown:

public class Relation
{
    public string City { get; set; } = default!;
    public int Kilometers { get; set; }
}

And this class Travle which should be DataSource of data grid view:
public class Travle
{
    public Relation {get; set; } = default!;

    public int Count { get; set; }
}


In picture you will see what I want to bind, so when I select Relation from first coulmn it should show Kilometers and when I enter Count it should create new object in DataSource.

Why this doesn't work when I have

dataGridViewTravles.DataSource = new List<Travle>();


I don't have option to add rows in data grid view?

P.S Application is written in WinForms.
image.png
Was this page helpful?