C
C#11mo ago
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; }
}
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; }
}
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>();
dataGridViewTravles.DataSource = new List<Travle>();
I don't have option to add rows in data grid view? P.S Application is written in WinForms.
No description
2 Replies
Mayor McCheese
Mayor McCheese11mo ago
Try to add a call to the data grid refresh after re|setting the data source
Mayor McCheese
Mayor McCheese11mo ago
Control.Refresh Method (System.Windows.Forms)
Forces the control to invalidate its client area and immediately redraw itself and any child controls.

Did you find this page helpful?