Hello! I need to make the user enter data into TextBoxes, they were saved in the list and added to the DataGridView. I made adding to the list, but I don’t know how to output data from the list to the DataGridView.

using System; using System.Collections.Generic; using System.Windows.Forms; namespace TransportSchedule { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public struct Transport { public string cityDeparture; public string cityDestination; public string dateDeparture; public string dateDestination; public double price; public Transport(string cityDeparture, string cityDestination, string dateDeparture, string dateDestination, double price) { this.cityDeparture = cityDeparture; this.cityDestination = cityDestination; this.dateDeparture = dateDeparture; this.dateDestination = dateDestination; this.price = price; } } List<Transport> transList = new List<Transport>(); private void addButton_Click(object sender, EventArgs e) { Transport transport = new Transport(cityDepartureBox.Text, cityDestinationBox.Text, dateDepartureBox.Text, dateDestinationBox.Text, Double.Parse(priceBox.Text)); transList.Add(transport); } 
  • dataGridView.DataSource = transList; . And replace the fields with properties. And class instead of structure. - Alexander Petrov
  • I did this, but if I make changes to the list (delete the item, etc.), then these changes are not displayed on the DataGridVIew, but I need the changes to be displayed - Bogdan
  • Questions should not be asked in the comments. And in general, one topic - one question. In theory, you need to ask a separate question. And this close, giving it an answer and accepting. By Subject: Instead of List , BindingList or ObservableCollection should be used. - Alexander Petrov

0