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 PetrovList,BindingListorObservableCollectionshould be used. - Alexander Petrov